0

リストビューのクリックに以下のコードを使用しています。しかし、それは私にとってはうまくいきません

     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

これを試して

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 に答える