在我的应用中,我有以下代码:
// Populate the ListView w/ all rows
Cursor data = appDBHelper.getAppDataAllBonuses();
listView.setAdapter(new SimpleCursorAdapter(this, R.layout.bonus_list_row_item, data,
new String[] {"sCode", "sName", "sCategory", "sCity", "sState"},
new int[] {R.id.bonusListCode, R.id.bonusListName, R.id.bonusListCategory, R.id.bonusListCity, R.id.bonusListState}, 0));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//use the position variable to get the list item from the list
String tappedBonus = ((TextView) findViewById(R.id.bonusListCode)).getText().toString();
Log.e(TAG,"goToCaptureBonus, tapped bonus = " + tappedBonus);
Intent goToCaptureBonus = new Intent(bonusListing.this,captureBonus.class);
goToCaptureBonus.putExtra("codeTapped",tappedBonus);
startActivity(goToCaptureBonus);
}
});
当我运行我的应用程序并点击一行时,我为bonusListCode获取的值就是最上面一行。我认为我的问题是我没有适当地使用该位置来找到正确的视图,但是我不确定如何编辑代码来做到这一点。
如何正确使用位置在实际点击的行中获取视图的值?