以下是我班级的代码:
public class SimpleCursorAdapterConLogoActivity extends ListActivity
{
private DatabaseHelper databaseHelper;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
databaseHelper = new DatabaseHelper(this);
String categoria=getIntent().getExtras().getString("categoria");
Cursor c = databaseHelper.getProdottiByCategoria(categoria);
startManagingCursor(c);
setListAdapter(new ProdottiSimpleCursorAdapter(this, c));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
TextView prodotto= (TextView) findViewById(R.id.prodotto);
Cursor cursor=databaseHelper.getInfoProdotto(prodotto.getText().toString());
startManagingCursor(cursor);
Intent nextScreen= new Intent(this,SchedaProdotto.class);
while(cursor.moveToNext())
{
String name= cursor.getString( cursor.getColumnIndex("Name") );
String price= cursor.getString(cursor.getColumnIndex("Price"));
String link_image=cursor.getString(cursor.getColumnIndex("Link_image"));
String descrizione= cursor.getString( cursor.getColumnIndex("Description") );
nextScreen.putExtra("name",name);
nextScreen.putExtra("price", price);
nextScreen.putExtra("link_image", link_image);
nextScreen.putExtra("description",description);
}
startActivity(nextScreen);
}
@Override
protected void onDestroy()
{
super.onDestroy();
databaseHelper.close();
}
}
我只获得第一个项目的TextView的名称。 这是因为我在onListItemClick方法中使用:
TextView prodotto= (TextView) findViewById(R.id.prodotto);
我不知道如何获取与列表中所选项目相关的TextView名称。
答案 0 :(得分:0)
如果要扩展CursorAdapter
,l.getItemAtPosition(position)
,则返回表示您单击的行的光标
@Override
protected void onListItemClick(ListView l, View v, int position, long id {
Cursor cursor = (Cursor) l.getItemAtPosition(position)
Intent nextScreen= new Intent(this,SchedaProdotto.class);
String name= cursor.getString( cursor.getColumnIndex("Name") );
String price= cursor.getString(cursor.getColumnIndex("Price"));
String link_image=cursor.getString(cursor.getColumnIndex("Link_image"));
String descrizione= cursor.getString( cursor.getColumnIndex("Description") );
nextScreen.putExtra("name",name);
nextScreen.putExtra("price", price);
nextScreen.putExtra("link_image", link_image);
nextScreen.putExtra("description",description);
startActivity(nextScreen);
}
应该这样做