我使用下面的代码进行listview点击。但这对我不起作用
public class ApparelsSubcatBrand extends ListActivity{
int position_list_v;
//ListAdapter adapter;
String urlImg, pid, pname, mrp, shipping, sellinprice = null, prodSize,
selSize,cbValue;
ListView listView1;
protected SQLiteDatabase sqlitedatabase_obj;
Cursor cursor;
public static String[] title_array ;
public static String[] description_array ;
protected ListAdapter adapter;
SQLiteDatabase dh;
String[] product_name = {};
int[] to_for_text_in_list = {R.id.title_info_txt_v};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.apparels_subcat_brand);
AndroidContext.setContext(this);
sqlitedatabase_obj = DataBaseHelper.getInstance().getDb();
listView1 = ( ListView ) findViewById(R.id.list);
cursor = sqlitedatabase_obj.rawQuery("SELECT _id, Key_ProductName , Key_SellingPrice FROM APPARELS_SUBCAT_BRAND WHERE Key_ProductName LIKE ? AND Key_SellingPrice LIKE ? ",new String[]{"%","%"});
final SimpleCursorAdapter simple=new SimpleCursorAdapter(this, R.layout.appareal_listview_text ,cursor, new String[]{"Key_ProductName","Key_SellingPrice"} , new int[] {R.id.title_info_txt_v,R.id.description_info_txt_v});
setListAdapter(simple);
}
@Override
public void onListItemClick(ListView parent, View view, int position,
long id) {
//position_list_v = position;
Intent intent = new Intent(ApparelsSubcatBrand.this,BuyNowOffline.class);
Cursor cursor = (Cursor)adapter.getItem(position);
intent.putExtra("product_id", cursor.getInt(cursor.getColumnIndex("Key_Product_ID")));
startActivity(intent);
}
点击事件未生成。这是我活动的总代码。我希望当我点击第一个项目然后它从该项目的数据库中检索相应的product_id
答案 0 :(得分:1)
我想这个问题与我以前遇到的问题类似,但是由于你没有显示你的适配器视图xml或代码,我不能给你提示性的代码,但你可以看到answer 。
希望这可以帮助你:)
答案 1 :(得分:0)
试试这个,
ListView lv = getListView();
lv.setTextFilterEnabled(true);
// Bind onclick event handler
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// Put in your code here, what you wanted trigger :)
if(your_condition){
Intent intent = new Intent(ApparelsSubcatBrand.this,BuyNowOffline.class);
// Cursor cursor = (Cursor)adapter.getItem(position);
intent.putExtra("product_id", cursor.getInt(cursor.getColumnIndex("_id")));
startActivity(intent);
}
}
});
您必须在AndroidManifest文件中添加您的活动
<activity android:name = ".BuyNowOffline"/>
答案 2 :(得分:0)
试试这个
public void onListItemClick(ListView parent, View view, int position, long id) {
Intent intent = new Intent(ApparelsSubcatBrand.this,BuyNowOffline.class);
intent.putExtra("product_id", id);
startActivity(intent);
}
获取其他活动中的值
long product_id= getIntent().getLongExtra("product_id", 0);
答案 3 :(得分:0)
你可以尝试这个例子:
lv.setAdapter(new ArrayAdapter(ClassName.this)); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @覆盖 public void onItemClick(AdapterView arg0,View arg1,int arg2,long arg3) { } });
希望它有效