我正在使用python -m CGIHTTPServer 8000
生成我的应用数据库中的列表:
SimpleCursorAdapter
如果我使用ListView和ListAdapter,我会设置长按一下监听器:
SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(getActivity(),
android.R.layout.simple_list_item_1, mCursor,
new String[] { DataManager.TITLE },
new int[] { android.R.id.text1 }, 0);
setListAdapter(cursorAdapter);
但由于我没有明确声明ListView list = (ListView) findViewById(R.id.listView);
list.setAdapter(mAdapter); // set the list view adapter
// enable long clicking on the list item
list.setLongClickable(true);
// detect long clicks and respond accordingly
list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
// do stuff
return true;
}
});
,我不能这样做。如何使用ListView
生成的列表?
答案 0 :(得分:1)
ListActivity
或ListFragment
那么你可以做的就是在onViewCreated()
而不是onCreateView()
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
// do stuff
return true;
}
});
答案 1 :(得分:0)
你不是这样使用SimpleCusrsorAdapter吗?
SimpleCursorAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.listitemlayout, c, from, to);
ListView list = (ListView)findViewById(R.id.listView);
list.setAdapter(adapter);
你在做什么
setListAdapter(CursorAdapter的)