вот мой макет main.xml;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/android:list" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1" android:visibility="visible" android:clickable="true"/>
</LinearLayout>
Вот MainActivity, которая расширяет ListActivity;
public class MainActivity extends ListActivity {
private final List<SpinnerEntry> spinnerContent = new LinkedList<SpinnerEntry>();
private ListView contactListView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
contactListView=getListView();
queryAllRawContacts();
registerForContextMenu(getListView());
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent i = new Intent(this, ContactDetailsActivity.class);
i.putExtra("hello", id);
// Activity returns an result if called with startActivityForResult
startActivity(i);
}
private void queryAllRawContacts() {
final String[] projection = new String[] {
RawContacts.CONTACT_ID, // the contact id column
RawContacts.DELETED // column if this contact is deleted
};
final Cursor rawContacts = managedQuery(
RawContacts.CONTENT_URI, // the uri for raw contact provider
projection,
null, // selection = null, retrieve all entries
null, // not required because selection does not contain parameters
null); // do not order
final int contactIdColumnIndex = rawContacts.getColumnIndex(RawContacts.CONTACT_ID);
final int deletedColumnIndex = rawContacts.getColumnIndex(RawContacts.DELETED);
spinnerContent.clear();
if(rawContacts.moveToFirst()) { // move the cursor to the first entry
while(!rawContacts.isAfterLast()) { // still a valid entry left?
final int contactId = rawContacts.getInt(contactIdColumnIndex);
final boolean deleted = (rawContacts.getInt(deletedColumnIndex) == 1);
if(!deleted) {
spinnerContent.add(queryDetailsForContactSpinnerEntry(contactId));
}
rawContacts.moveToNext(); // move to the next entry
}
}
rawContacts.close();
final ContactsSpinnerAdapater adapter = new ContactsSpinnerAdapater(spinnerContent, this);
contactListView.setAdapter(adapter);
}
А вот мой класс customadapter, который называется ContactsSpinnerAdapater;
public class ContactsSpinnerAdapater extends BaseAdapter implements
SpinnerAdapter{
private final List<SpinnerEntry> content;
private final Activity activity;
public ContactsSpinnerAdapater(List<SpinnerEntry> content,
Activity activity) {
super();
this.content = content;
this.activity = activity;
}
public int getCount() {
return content.size();
}
public SpinnerEntry getItem(int position) {
return content.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView,
ViewGroup parent) {
final LayoutInflater inflater = activity.getLayoutInflater(); // default layout inflater
final View spinnerEntry = inflater.inflate(
R.layout.row, null); // initialize the layout from xml
final TextView contactName = (TextView) spinnerEntry
.findViewById(R.id.cName);
final ImageView contactImage = (ImageView) spinnerEntry
.findViewById(R.id.userIcon);
final SpinnerEntry currentEntry = content.get(position);
contactName.setText(currentEntry.getContactName());
contactImage.setImageBitmap(currentEntry.getContactPhoto());
spinnerEntry.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
}});
return spinnerEntry;
}
}
Проблема заключается в том, что, что бы я ни пытался, я не смог запустить намерение ContacDetailsActivity при щелчке по любому элементу списка. В основном слушатель как-то не активируется. Не могли бы вы взглянуть на код и сказать, где я его пропускаю?