android 在一个listview中怎么给每一项的button监听点击事件
展开全部
首先你说的东西是一个误区,不是每一项button而是list里面的item,其次,将item进行点击监听,我写一个点击监听的方法
mylistview = (ListView)findViewById(R.id.listview);
list.add("LinearLayout");
list.add("AbsoluteLayout");
list.add("TableLayout");
list.add("RelativeLayout");
list.add("FrameLayout");
ArrayAdapter<String> myArrayAdapter = new ArrayAdapter<String>
(this,android.R.layout.simple_list_item_1,list);
mylistview.setAdapter(myArrayAdapter);
mylistview.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
if(list.get(arg2).equals("LinearLayout"))
{
Intent intent = new Intent("com.wps.android.LINEARLAYOUT");
startActivity(intent);
}
if(list.get(arg2).equals("AbsoluteLayout"))
{
Intent intent = new Intent("com.wps.android.ABSOLUTELAYOUT");
startActivity(intent);
}
if(list.get(arg2).equals("TableLayout"))
{
Intent intent = new Intent("com.wps.android.TABLELAYOUT");
startActivity(intent);
}
if(list.get(arg2).equals("RelativeLayout"))
{
Intent intent = new Intent("com.wps.android.RELATIVELAYOUT");
startActivity(intent);
}
if(list.get(arg2).equals("FrameLayout"))
{
Intent intent = new Intent("com.wps.android.FRAMELAYOUT");
startActivity(intent);
}
}
});
mylistview = (ListView)findViewById(R.id.listview);
list.add("LinearLayout");
list.add("AbsoluteLayout");
list.add("TableLayout");
list.add("RelativeLayout");
list.add("FrameLayout");
ArrayAdapter<String> myArrayAdapter = new ArrayAdapter<String>
(this,android.R.layout.simple_list_item_1,list);
mylistview.setAdapter(myArrayAdapter);
mylistview.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
if(list.get(arg2).equals("LinearLayout"))
{
Intent intent = new Intent("com.wps.android.LINEARLAYOUT");
startActivity(intent);
}
if(list.get(arg2).equals("AbsoluteLayout"))
{
Intent intent = new Intent("com.wps.android.ABSOLUTELAYOUT");
startActivity(intent);
}
if(list.get(arg2).equals("TableLayout"))
{
Intent intent = new Intent("com.wps.android.TABLELAYOUT");
startActivity(intent);
}
if(list.get(arg2).equals("RelativeLayout"))
{
Intent intent = new Intent("com.wps.android.RELATIVELAYOUT");
startActivity(intent);
}
if(list.get(arg2).equals("FrameLayout"))
{
Intent intent = new Intent("com.wps.android.FRAMELAYOUT");
startActivity(intent);
}
}
});
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询