我已经编写了设置列表的代码,现在我想要可点击的列表如何做到这一点。当我点击特定项目时它应该是可点击的。当我点击 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);
}
}