开发者

I want to add List view below some of my components

I am new in android and i am trying to add list view under some of my controls. I am not getting it how to do this. And i have already used Scroll view in xm开发者_StackOverflow中文版l as controls are more. So plz any one can help me out of this.? Thanks in advanced. I put link of my xml . 1[here]


To add ListView to your Project, use the following code in your java file.

  String lv_arr[]={"Lamborghini","Audi","Ferrari","BMW"};  // add componenets here

    final ListView lst = (ListView)findViewById(R.id.listView1);

    lst.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , lv_arr));

   lst.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> a, View v, int position, long id) {

            if(((position))==0) {
                //Any code you want e.g start a new activity
                               startActivity(new Intent(this, xyz.class);
        }
    }
  });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜