2016-04-14 3 views
1
  • ここでは、私は、カートのアイテムを表示するには、このコードを使用しています、と私は追加したいシンプルなCursorAdapter
  • を使用してカスタムListViewを表示するために使用していたコードです私は問題が何であるかを把握することはできませんよアンドロイド開発に新しいですしたよう
  • ListViewでボタン

myDbHelper.openDataBase(); 

    final Cursor ictemp = myDbHelper.getOrdredItems(myDbHelper); 
    if (ictemp != null) { 

     ictemp.moveToFirst(); 
     count = ictemp.getCount(); 
     Log.d("count", "count===" + count); 

     String[] from = new String[] { "item_name", "item_rate", "qty", 
       "unit" }; 
     int[] to = new int[] { R.id.tv_Name, R.id.tv_Rate, R.id.et_qty, 
       R.id.tv_unit }; 

     final SimpleCursorAdapter sc = new SimpleCursorAdapter(this, 
       R.layout.list_row2, ictemp, from, to, 0); 

     final Cursor crs = myDbHelper.getTotal(myDbHelper); 
     if (crs != null) { 

      crs.moveToFirst(); 

      String total = crs.getString(0); 
      Gtotal.setText("Rs." + total); 
      tvcount.setText("" + count); 



     } 

     lv.setAdapter(sc); 

     lv.setOnItemClickListener(new OnItemClickListener() { 

      @Override 
      public void onItemClick(AdapterView<?> arg0, View view, 
        final int pos, long arg3) { 


       remove = (Button) arg0.findViewById(R.id.btn_remove); 
       switch (arg0.getId()) { 

       case R.id.btn_remove: 

        Toast.makeText(ctx, "Clicked on " + pos, 
          Toast.LENGTH_SHORT).show(); 

        break;} 



      } 
     }); 
+0

を助け

final CustomAdapter sc = new CustomAdapter(this,R.layout.list_row2,ictemp, from, to, 0); lv.setAdapter(sc) 

希望によりActivityでそれを使用して扱う見つけるbindView方法オーバーライドしますか? –

+0

私のremove(item)ボタンはカスタム行にありますが、今はlv.setOnItemClickListenerを使用しています。リストビューからアイテムを削除するたびにonclicklistnerを呼び出すようにします。 –

答えて

1

SimpleCursorAdapterを拡張するCustomAdapterを作成することです。
その後bindView
は、Buttonその後、onClickEvent

public class CustomAdapter extends SimpleCursorAdapter { 

    private Context mContext; 
    private Context appContext; 
    private int layout; 
    private Cursor cr; 
    private final LayoutInflater inflater; 

    public CustomAdapter(Context context, int layout, Cursor c, String[] from, int[] to) { 
     super(context, layout, c, from, to); 
     this.layout = layout; 
     this.mContext = context; 
     this.inflater = LayoutInflater.from(context); 
     this.cr = c; 
    } 

    @Override 
    public View newView(Context context, Cursor cursor, ViewGroup parent) { 
     return inflater.inflate(layout, null); 
    } 

    @Override 
    public void bindView(View view, Context context, Cursor cursor) { 
     super.bindView(view, context, cursor); 
     ... 
     TextView tv_Name = (TextView) view.findViewById(R.id.tv_Name); 
     tv_Name.setText(...); 
     ... 
     Button btnRemove = (Button) view.findViewById(R.id.btn_remove); 
     btnRemove.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       // button click 
       // Remove your item here 

      } 
     }); 
    } 
} 

はこれが

削除ボタンを置く
+0

私はlistviewでボタンの位置を取得できますか? ? –

+0

はうまく働いた:)また私は位置を得る方法を見つけたthanksss多く –

関連する問題