0

3つのテキストボックスと各行に1つのチェックボックスがあるlisviewがあります。次のコードスニペットを使用して、チェックされたチェックボックスの正確な位置を取得しました。これはうまく機能しましたが、今は入れたくない listView.setOnItemClickListener ので、リストビューの項目や行をクリックするのではなく、ボタンでチェックした項目を削除したいのですが、目標を達成するためにこれらのコードをどこに配置すればよいかわかりません。事前に懸念や提案をいただければ幸いです。

listView.setOnItemClickListener(new OnItemClickListener() {

    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {

        CheckBox cbx = (CheckBox)view.findViewById(R.id.ChkOrder);

            int firstPosition = listView.getFirstVisiblePosition();
            for(int i=firstPosition;i<listView.getCount();i++){
            View v=listView.getChildAt(i);
            cbx = (CheckBox)v.findViewById(R.id.ChkOrder);
            if(cbx.isChecked()){

                 Toast.makeText(getApplicationContext(), 
                                 "Checked position " + goods.get(i), 
                                  Toast.LENGTH_SHORT).show();
                 checkedItemPosition=i;


           }
        }

     }

});
4

1 に答える 1

0

これは、好みのボタンに配置listviewし、コードで宣言したビューに変更することで解決されます。

Button Delete=(Button)findViewById(R.id.DeleteButton);
       DeleteGoods.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                /** Getting the position of the currently selected item**/
                //////////////////////////////////
                 CheckBox cbx = (CheckBox)listView.findViewById(R.id.ChkOrder);

                    int firstPosition = listView.getFirstVisiblePosition();
                    for(int i=firstPosition;i<listView.getCount();i++){
                    View v1=listView.getChildAt(i);
                    cbx = (CheckBox)v1.findViewById(R.id.ChkOrder);
                    if(cbx.isChecked()){

                        // Toast.makeText(getApplicationContext(), 
                               //          "Checked position " + goods.get(i), 
                                //          Toast.LENGTH_SHORT).show();
                         checkedItemPosition=i;
                    }
                    }
于 2013-02-17T06:28:08.133 に答える