2013-01-16 77 views
2

我已经编写了用于创建下面显示的一些数组的列表的代码!代码正常运行,输出如预期!使用数组列表适配器设计Android列表视图

更新人的相同的概率:nice tutorial for custom listview

MainActivity.java

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

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

    String[] items = { "some", "fancy", "items", "to", "show" }; 

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
       R.layout.listitem, items); 

    listView1.setAdapter(adapter); 
    } 

activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" > 

    <ListView 
    android:id="@+id/listView1" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" /> 

    </RelativeLayout> 

listview.xml

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:textSize="20sp" 
android:padding="22dp" 
android:gravity="center_horizontal" 
/> 

我想完成什么?

  1. 改变颜色和每个列表中的项目中的文本字体不同one..and做轻拍他们一些任务...

  2. 也有可能得到内的另一个列表视图例如,相同的列表视图 。如果我点击一个列表项目,它会再次向我显示一个列表(一种子列表),并在同一活动(或屏幕)上显示不同列表项目,并且可以在点击子列表项目时完成一些操作。因为我是新android开发

详细答案是感激.. 谢谢!

+0

你说的是_Customized ListView_? –

+0

是的!一个listview可以很容易地定制,并与arrayadapter – user1979237

+0

一起工作看看我的答案。 –

回答

0
1.change color and font of the text in each list item to a different one..and do some task on 
    tapping on them... 
  • 创建自定义适配器,覆盖该适配器的getVIew(),并在它的颜色和文本 变化。
  • 覆盖您的ListView的onItemClick()。完成列表项目的点击事件 。

现在

2. also is it possible to get another listview inside the same listview eg. if I click on a 
    list item it again shows me a list (kind of a sub list) with different list items on that 
    same activity(or screen).and some action could be done on tapping the sub list items. 

3. what are my other list styling options.. 

而且Tutorial

+0

您可以提供一个简单的示例代码或将我引向包含该示例的网站!谷歌搜索不提供我可以理解的东西 – user1979237

0

你要寻找到一个定制ArrayAdapter这里http://www.vogella.com/articles/AndroidListView/article.html

看出,将采取的第一个和第三个问题的照顾。至于第二个对于ListView的默认实现来说是不可能的,但有些库可以让你创建下拉列表项。

+0

谢谢..将有一个阅读! – user1979237

+0

@ user1979237,那么您可能想要接受该答案。 – walters