2014-03-19 77 views
-1

美好的一天,请我需要知道如何做一个列表项目点击能够在Android ..我正在开发一个圣经10个版本为我在学校的最后一年的项目,我需要要知道我如何点击一个列表项目,它会带我到另一个页面上的列表项目。我怎样才能让列表项目在Android上可点击

一样,如果我对发生点击,它会带我去章节下的另一个列表视图布局发生..

我一直在这个长,我需要提交项目上周一经久不衰

我一直在写它几个月,并没有得到它

+1

欢迎来到堆栈溢出!为了得到积极的回应,请告诉我们你已经尝试了什么。考虑在你的文章中添加[MCTRE](http://stackoverflow.com/help/mcve)。 –

回答

0

只需使用一个ArrayList类型来存储所有的值,你想给列表。然后使用ArrayAdapter将所有这些列表项放入列表中。这样,所有的项目都可以点击。

例如 - >

public class CreateList extends ListActivity { 

    ArrayList<String> myList=new ArrayList<String>; 
    ArrayAdapter<String> myAdapter; 

    protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.createlist); 

      myAdapter=new ArrayAdapter<String> (CreateList.this,android.R.layout.simple_list_item_1,myList); 
      setListAdapter(myAdapter); 

myList.add("genesis"); 
myAdapter.notifyDataSetChanged(); 
} 

    } 

你可以让你的XML文件 - >

createlist.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

     <ListView 
      android:id="@android:id/list" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 

    </LinearLayout> 

希望这有助于。 :)

+0

我仍然无法得到它..这是我的代码 – user3437883

+0

你使用了相同的代码? – Aradhna

相关问题