ListAdapter経由でリストにいくつかのSQLデータを表示しています。リスト内の各アイテムにクリックリスナーを設定しようとする場合を除いて、すべて正常に動作します。いずれかの項目をクリックすると何も起こりません。エラーメッセージは表示されず、ただ静かに失敗します。android onItemClickが自動的に失敗します
public class Notes extends ListActivity implements OnClickListener {
private static final String TAG = "Notes";
private NotesData notes;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
notes = new NotesData(this);
try {
Cursor cursor = getNotes();
showNotes(cursor); /* set the cursor to the listadapter */
ListView ls = (ListView) findViewById(android.R.id.list);
ls.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,View v,
int position,long id) {
Toast.makeText(getApplicationContext(),"clicked",
Toast.LENGTH_SHORT).show();
}
});
} finally {
notes.close();
}
}
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">
<Button
android:id="@+id/new_note_button"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/new_note"/>
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/empty"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/empty"/>
</LinearLayout>
は、私が欠けているものはありますか?
また、リストビューが有効、クリック可能、フォーカス可能に設定されていることを確認してください。 –
FYI 'android:id =" @ + id/empty "'は 'android:id = "@アンドロイド:id/empty"です。 – idbrii
onItemClickは呼び出されません。リストビューをクリック可能かつフォーカス可能に設定することは役に立たなかった。 – herpderp