IM相當新的到Android,所以我道歉,如果這是一個小白上下的問題(:幫助,ListView和R.layout.main(安卓)
我設計我的名單下面這裏找到了例子:http://android-er.blogspot.com/2010/06/custom-arrayadapter-with-with-different.html
,但我想知道的是如何將我去加入的setContentView(R.layout.main),這樣我可以顯示列表以及其他(XML)元素的任何意見(
感謝?
IM相當新的到Android,所以我道歉,如果這是一個小白上下的問題(:幫助,ListView和R.layout.main(安卓)
我設計我的名單下面這裏找到了例子:http://android-er.blogspot.com/2010/06/custom-arrayadapter-with-with-different.html
,但我想知道的是如何將我去加入的setContentView(R.layout.main),這樣我可以顯示列表以及其他(XML)元素的任何意見(
感謝?
您只需編輯您的main.xml以查看whate你想讓它看起來,例如:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<View android:id="@+id/emptyview"
android:layout_height="30dp"
android:layout_width="fill_parent"
/>
<ListView android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="true"
android:stackFromBottom="true"
android:layout_below="@id/emptyview"
android:headerDividersEnabled="true"
/>
</RelativeLayout>
改變你的活動只擴展活動,而不是ListActivity。最後,在你的活動,你可以再取你的列表視圖:
ListView list = (ListView) findViewById(R.id.listview);
,做任何你需要的名單做。
給它添加一個ListView控件
<ListView android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/myListView"
android:divider="#ffa500" android:dividerHeight="1px"
android:background="@drawable/somedrawable_xml"
android:choiceMode="singleChoice"></ListView>
somedrawable_xml.xml
可以是任何可繪製的例子:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00ffa500" />
<stroke android:width="2dp" android:color="#ffffa500" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
添加布局XMLFILE myLayout.xml
例如:(我加了示範ImageView的),反正最重要的是TextView的
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dasdasd">
<TextView android:text="TextView" android:layout_height="wrap_content"
android:id="@+id/thisIsTheTextView" android:layout_width="wrap_content" android:textAppearance="?
android:attr/textAppearanceLarge"></TextView>
<ImageView android:src="@drawable/icon" android:id="@+id/imageView1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentRight="true"></ImageView>
最後你的Activity
ArrayAdapter myAD=new ArrayAdapter(mContext,R.layout.myLayout,R.id.thisIsTheTextView,new String[] {"item1", "item2", "item3", "item4", "item5"});
myListView.setAdapter(myAD);
你好,謝謝你的迴應,但哪部分代碼取代最後一段? – 92Jacko
你可以將它添加到'onCreate()'來填充ListView ..這是你'setContentView(R.layout.main)''我給你所有的代碼 –
感謝中的id建議(:..但是當我嘗試它時,我得到了一個關閉的力量:/有什麼想法? – 92Jacko
..現在,奇怪。代碼的一切都很好,我剛剛重新安裝並重新啓動應用程序,然後它很好(: – 92Jacko
日食有時:)有沒有:) – Maggie