1

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?

  1. change color and font of the text in each list item to a different one..and do some task on tapping on them...

  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.

Detailed answers are appreciated as I am new to android development.. Thanks!

user1979237
  • 11
  • 2
  • 7

4 Answers4

0

You'll want to look into a custom ArrayAdapter as seen here http://www.vogella.com/articles/AndroidListView/article.html

That will take care of the first and third questions. As for the second one that's not possible with the default implementation of ListView but there are libraries that enable you to create drop down listItems.

Paul Thompson
  • 3,290
  • 2
  • 31
  • 39
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...
  • Make a Custom Adapter, override getVIew() of that adapter and make changes on color and text in it.
  • override onItemClick() for your ListView. to accomplish click event for list item.

Now

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..

And Tutorial

user370305
  • 108,599
  • 23
  • 164
  • 151
  • could you provide a simmple sample code or refer me to site containing that sample! google searching doesn't provide me with understandable stuff – user1979237 Jan 16 '13 at 09:18
0

For 1st question, you can use paulthom12345' answer.

2nd question: You have to use exapandableListView

for more details please see: Android ExpandableListView - Looking for a tutorial

3rd question is not constructive and very vague. Please edit the question and explain in greater detail.

Community
  • 1
  • 1
Shrikant Ballal
  • 7,067
  • 7
  • 41
  • 61
0
  1. Use Customized List View for it.

  2. It is not exactly possible to have a list inside a list. Instead of it, use expandable list

  3. Have a look at Android Listview with different layout for each row

Community
  • 1
  • 1
Sahil Mahajan Mj
  • 11,033
  • 8
  • 53
  • 100