0

我正在使用下面的代码进行 listview click 。但这对我不起作用

     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

4

4 回答 4

1

我猜这个问题和我之前遇到的问题类似,但是因为你没有显示你的适配器视图 xml 或代码,我不能给你提示代码,但是你可以看到这个答案

希望这可以帮到你 :)

于 2013-07-04T10:51:21.460 回答
0

你可以试试这个例子:

lv.setAdapter(new ArrayAdapter(ClassName.this)); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView arg0, View arg1,int arg2, long arg3) { } });

希望它有效

于 2013-09-02T12:54:21.723 回答
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);
于 2013-07-04T09:53:49.313 回答
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"/>
于 2013-07-04T09:46:29.890 回答