-1

リストを設定するコードを書きましたが、クリック可能なリストを作成する方法が必要です。特定のアイテムをクリックすると、クリック可能になるはずです。TrxtViewをクリックすると、いくつかのアクションが発生し、クリックするとボタンを押すと、別のアクションが発生します。

私のコードは

public class Downloadlist extends ListActivity {
            private List<String> item = null;
            private List<String> path = null;
            private String root="/sdcard";
            private TextView myPath;
            ListView lv1;

            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.mydownload);
                myPath = (TextView)findViewById(R.id.path);
                lv1=(ListView)findViewById(R.id.list);
                getDir(root);
            }
            private void getDir(String dirPath)
            {
                myPath.setText("Location: " + dirPath);
                item = new ArrayList<String>();
                path = new ArrayList<String>();
                File f = new File(dirPath);
                File[] files = f.listFiles();
                if(!dirPath.equals(root))
                {
                    item.add(root);
                    path.add(root);
                    item.add("../");
                    path.add(f.getParent());
                }
                for(int i=0; i < files.length; i++)
                {
                    File file = files[i];
                    path.add(file.getPath());
                    if(file.isDirectory())
                        item.add(file.getName() + "/");
                    else
                        item.add(file.getName());
                }
                Log.d("itemssssssss", item.toString());
                ArrayAdapter<String> fileList =
                        new ArrayAdapter<String>(this, R.layout.rowmydownload,R.id.rowtext, this.item);
                setListAdapter(fileList);

            }
        }
4

1 に答える 1

0

リストビュー項目にボタンがあると、そのビューはクリックできなくなります。したがって、ボタンの代わりに imageView を使用し、listView の onItemClickListener をアクティビティに配置します。アダプターでは、Textview と ImageView に OnClickListener を配置します。

于 2012-06-07T13:36:01.223 に答える