Help With Listview And R.layout.main (android)
im quite new to android, so i apologise if this is a noob-ish question (: i designed my list following the example found here: http://android-er.blogspot.com/2010/06/custom-arrayad
Solution 1:
You just edit your main.xml to look whatever you want it to look, eg:
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"><Viewandroid:id="@+id/emptyview"android:layout_height="30dp"android:layout_width="fill_parent"
/><ListViewandroid: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>
Change your activity to extend only Activity, not ListActivity. Finally, in your activity you can then fetch your list view with:
ListViewlist= (ListView) findViewById(R.id.listview);
and do whatever you need to do with the list.
Solution 2:
- You create your main.xml
Add to it a 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
could be any drawable example:
<?xml version="1.0" encoding="UTF-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"><solidandroid:color="#00ffa500" /><strokeandroid:width="2dp"android:color="#ffffa500" /><paddingandroid:left="1dp"android:top="1dp"android:right="1dp"android:bottom="1dp" />
Add a layout xmlFile myLayout.xml
example: (I added imageView for demonstration) anyway what is important is the id of the textview
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns: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"><TextViewandroid:text="TextView"android:layout_height="wrap_content"android:id="@+id/thisIsTheTextView"android:layout_width="wrap_content"android:textAppearance="?
android:attr/textAppearanceLarge"></TextView><ImageViewandroid:src="@drawable/icon"android:id="@+id/imageView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"></ImageView>
finally in your Activity
ArrayAdapter myAD=newArrayAdapter(mContext,R.layout.myLayout,R.id.thisIsTheTextView,newString[] {"item1", "item2", "item3", "item4", "item5"});
myListView.setAdapter(myAD);
Post a Comment for "Help With Listview And R.layout.main (android)"