android怎样获得ListView上被选中的数据
2个回答
展开全部
setOnItemClickListener();监听被点击的item
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
// 绑定数据生成列表
ArrayList<HashMap<String, String>> list = InitFileList(fileSavedPath);
SimpleAdapter listItemAdapter = new SimpleAdapter(this, list,
R.layout.listitem, new String[] { "name", "status" },
new int[] { R.id.textViewFilename, R.id.textViewStatus });
ListView lv = (ListView) findViewById(R.id.listViewFilelist);
lv.setAdapter(listItemAdapter);
lv.setOnItemClickListener(itemclick);
}
OnItemClickListener itemclick = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
try {
String filename = fileList[arg2];
Intent intent = new Intent(ActFileList.this,
ActFileDownloader.class);
intent.putExtra("filename", filename);
intent.putExtra("serverip", serverip);
intent.putExtra("saveto", saveto);
startActivity(intent);
} catch (NullPointerException e) {
// 没有数据,不操作
}
}
};
ArrayList<HashMap<String, String>> list = InitFileList(fileSavedPath);
SimpleAdapter listItemAdapter = new SimpleAdapter(this, list,
R.layout.listitem, new String[] { "name", "status" },
new int[] { R.id.textViewFilename, R.id.textViewStatus });
ListView lv = (ListView) findViewById(R.id.listViewFilelist);
lv.setAdapter(listItemAdapter);
lv.setOnItemClickListener(itemclick);
}
OnItemClickListener itemclick = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
try {
String filename = fileList[arg2];
Intent intent = new Intent(ActFileList.this,
ActFileDownloader.class);
intent.putExtra("filename", filename);
intent.putExtra("serverip", serverip);
intent.putExtra("saveto", saveto);
startActivity(intent);
} catch (NullPointerException e) {
// 没有数据,不操作
}
}
};
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询