0
誰能告訴我爲什麼這在我的LG400f觸摸手機上不起作用,但在模擬器中單擊鼠標可以正常工作嗎?ListView onClick在模擬器中工作,但不在觸摸手機上
代碼
ListView listView = (ListView) findViewById(R.id.listContactsList);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_contacts, R.id.listContactsView, values);
listView.setAdapter(adapter);
listView.setClickable(true);
listView.setFocusable(true);
listView.setFocusableInTouchMode(true);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Object selection = (Object) parent.getItemAtPosition(position);
Toast.makeText(getApplicationContext(), selection.toString(), Toast.LENGTH_LONG).show();
// Toast is triggered with mouse click in emulator but not touch in phone
XML
<ListView
android:id="@+id/listContactsList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
tools:context=".ListContacts" />
嘗試改變線listView.setOnItemClickListener(新AdapterView.OnItemClickListener()爲 「listView.setOnItemClickListener(新OnItemClickListener(){}」 –
所以在設備上,'selection' 'null'或'onItemClick'沒有運行? – Sam
無法得到這個listView.setOnItemClickListener(new OnItemClickListener(){}去工作Jade – Mike