在ListView添加一个按钮 [英] add a button in a listView

查看:119
本文介绍了在ListView添加一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在每一个列表项,当用户preSS它打个电话添加一个按钮。但是,当用户preSS文字,没有什么happens..is这可能吗?这是我的code:

 公共类博物馆延伸活动{    / **当第一次创建活动调用。 * /
    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        的setContentView(R.layout.museum);
        ListView控件列表=(ListView控件)findViewById(R.id.list);        ArrayList的<&HashMap的LT;字符串,字符串>> MYLIST =新的ArrayList<&HashMap的LT;字符串,字符串>>();
        HashMap的<字符串,字符串>地图=新的HashMap<字符串,字符串>();
        map.put(名,哈尼亚考古博物馆);
        map.put(地址,Chalidon 21,哈尼亚);        mylist.add(地图);
        地图=新的HashMap<字符串,字符串>();
        map.put(名,拜占庭博物馆);
        map.put(地址,Theotokopoulou 82,哈尼亚);        mylist.add(地图);
        // ...
        ListAdapter mSchedule =新SimpleAdapter(这一点,MYLIST,R.layout.row_museum,
                    新的String [] {姓名,地​​址},新的INT [] {R.id.TextView01,R.id.TextView02});
        list.setAdapter(mSchedule);        list.setOnItemClickListener(新OnItemClickListener(){
         公共无效onItemClick(适配器视图<>母公司,观景,
                  INT位置,长的id){
                开关(位置)
                {
                   情况下0:
                            打破;
                   情况1:
                        打破;
                   案例2:
                        打破;
                   案例3:
                        打破;
                }
            }
          });
    }
}


解决方案

雅,你可以做。对于


  1. 您将创建包含的TextView和按钮列表行布局文件。

  2. 使用该布局定制ArrayAdapter内。

看到一个如在这网站

I want to add a button in every list item and when the user press it to make a phone call. But when the user press the text, nothing happens..is that possible? This is my code:

public class museum extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.museum); 


        ListView list = (ListView) findViewById(R.id.list);

        ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();


        HashMap<String, String> map = new HashMap<String, String>();
        map.put("name", "Archaeological Museum of Chania");
        map.put("address", "Chalidon 21 , Chania");

        mylist.add(map);
        map = new HashMap<String, String>();
        map.put("name", "Byzantine Museum");
        map.put("address", "Theotokopoulou 82 , Chania");

        mylist.add(map);
        // ...
        ListAdapter mSchedule = new SimpleAdapter(this, mylist, R.layout.row_museum,
                    new String[] {"name", "address"}, new int[] {R.id.TextView01, R.id.TextView02});
        list.setAdapter(mSchedule);



        list.setOnItemClickListener(new OnItemClickListener() {
         public void onItemClick(AdapterView<?> parent, View view,
                  int position, long id) {
                switch( position )
                {
                   case 0: 
                            break;
                   case 1:  
                        break;
                   case 2:  
                        break;
                   case 3:  
                        break;


                }
            }
          });
    }
}

解决方案

Ya you can do. For that

  1. You will have to create a layout file for the list row that contains the textview and the button.
  2. Use that layout inside a customized ArrayAdapter.

See an eg in this site.

这篇关于在ListView添加一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆