如何通过行的值列表视图中的一个按钮 [英] how to pass the value of row in listview to a button
本文介绍了如何通过行的值列表视图中的一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个自定义的列表视图
使用 SimpleAdapter
和每个列表视图的行中我把按钮有一个ID。
我想要得到的位置
每一行的传递按钮,但我有每行和每一个按钮的ID的我想在我的点击按钮的是找到行的位置,并开始另一个活动
请大家帮我
公共无效点击(视图v){
// RelativeLayout的NAVI =(RelativeLayout的)findViewById(R.layout.custom_row_view);
TextView的电视=(的TextView)findViewById(R.id.text1);
的ImageButton IM =(的ImageButton)findViewById(R.id.imageButton1);
LV的ListView =(ListView控件)findViewById(android.R.id.list);
INT位置= 0;
龙ID =的Long.parseLong((字符串)adapter.getItem(位置)); 我的意图= NULL;
开关(位置){
情况1:
I =新意图(这一点,ButtonActivity.class);
startActivity(ⅰ);
打破;
案例2:
I =新意图(这一点,PickerActivity.class);
startActivity(ⅰ);
打破;
}
解决方案
试试这个
listView.setOnItemClickListener(新AdapterView.OnItemClickListener(){ 公共无效onItemClick(适配器视图<>为arg0,ARG1查看,
最终诠释ARG2,长ARG3){ 最后ProgressDialog进度= ProgressDialog.show(
VechiclesDetails.this,,loadingString); progressBar.setIndeterminate(真);
progressBar.setIndeterminateDrawable(getResources()
.getDrawable(R.anim.progressbar_handler));
新主题(新的Runnable接口(){ 公共无效的run(){
尝试{
意图carDetail =新意图(
Details.this,
Screen.class);
carDetail.putExtra(指数,ARG2);
carDetail.putExtra(sellerId,SellerId);
startActivity(carDetail);
progressBar.dismiss();
}赶上(例外五){
progressBar.dismiss();
}
}
})。开始(); }
});
I have created a custom listview
using SimpleAdapter
and in each row of list view i put a button has single id.
I want to get the position
of each row to pass the button but i have a single button id for each row and I want when I click on button it find the position of row and start another activity
please help me
public void click(View v){
//RelativeLayout navi = (RelativeLayout)findViewById(R.layout.custom_row_view);
TextView tv = (TextView)findViewById(R.id.text1);
ImageButton im = (ImageButton)findViewById(R.id.imageButton1);
ListView lv=(ListView)findViewById(android.R.id.list);
int position = 0;
Long id=Long.parseLong((String) adapter.getItem(position));
Intent i=null;
switch(position){
case 1:
i=new Intent(this, ButtonActivity.class);
startActivity(i);
break;
case 2:
i = new Intent(this, PickerActivity.class);
startActivity(i);
break;
}
解决方案
try this
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
final int arg2, long arg3) {
final ProgressDialog progressBar = ProgressDialog.show(
VechiclesDetails.this, "", loadingString);
progressBar.setIndeterminate(true);
progressBar.setIndeterminateDrawable(getResources()
.getDrawable(R.anim.progressbar_handler));
new Thread(new Runnable() {
public void run() {
try {
Intent carDetail = new Intent(
Details.this,
Screen.class);
carDetail.putExtra("index", arg2);
carDetail.putExtra("sellerId", SellerId);
startActivity(carDetail);
progressBar.dismiss();
} catch (Exception e) {
progressBar.dismiss();
}
}
}).start();
}
});
这篇关于如何通过行的值列表视图中的一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文