2013-01-16 79 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