I have written the code for creating a list out of some arrays shown below! code runs properly and output is as expected!
update for people with same prob: 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"
/>
what I want to accomplish?
change color and font of the text in each list item to a different one..and do some task on tapping on them...
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.
Detailed answers are appreciated as I am new to android development.. Thanks!