以下是我的代码:
当我点击列表视图中的一行时,我没有看到任何Toast。有人能告诉我我犯了什么错误吗?
提前感谢。
public class TestActivity extends ListActivity {
private Cursor cursor;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
fillData();
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// Get the item that was clicked
Object o = this.getListAdapter().getItem(position);
String keyword = o.toString();
Toast.makeText(this, "You selected: " + keyword, Toast.LENGTH_LONG)
.show();
}
private void fillData() {
TermsData_DataHelper termsDataHelper = new TermsData_DataHelper(
TestActivity.this);
cursor = termsDataHelper.fetchAllCategories();
startManagingCursor(cursor);
String[] names = new String[] { "name" };
int[] to = new int[] { R.id.label };
// Now create an array adapter and set it to display using our row
SimpleCursorAdapter categories = new SimpleCursorAdapter(this,
R.layout.terms_row, cursor, names, to);
setListAdapter(categories);
}
}
当我点击列表视图中的一行时,我没有看到任何Toast。有人能告诉我我犯了什么错误吗?
提前感谢。
onListItemClick()
方法中设置断点并在调试模式下运行,可以确保该方法是否被调用,这可能会缩小可能出现问题的范围。 - Sven VikingonListItemClick()
处添加了一个断点,但当我点击列表行时,控制并没有到达那里。你能告诉我可能的错误是什么吗? - Mahendra Liya