-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 而不是按钮并将 onItemClickListener 放在活动中的 listView 中。在适配器中,为 Textview 和 ImageView 放置 OnClickListener。

于 2012-06-07T13:36:01.223 回答