我已经编写了设置列表的代码,现在我想要可点击的列表如何做。当我点击特定项目它应该是可点击的。我点击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);
}
}
答案 0 :(得分:0)
在listview项目中有一个按钮将使该视图无法点击。因此,使用imageView而不是按钮,并将onItemClickListener放入活动中的listView。在适配器中,为Textview和ImageView放置OnClickListener。