I am developing an application in which I created a custom list view:
List view code in the form:
<ListView android:id="@+id/listview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="15dip" android:divider="#623b42" android:dividerHeight="0.5dip" android:cacheColorHint="#00000000" android:overScrollMode="never" > </ListView>
And xml adapter:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_toLeftOf="@+id/textview_rupee_mlsaa" android:gravity="center_vertical" android:padding="15dip" android:textColor="@color/color_black" android:textSize="15sp" tools:ignore="SelectableText" /> <TextView android:id="@+id/textview2" android:layout_width="60sp" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:gravity="center_vertical" android:padding="15dip" android:textColor="@color/color_black" android:textSize="15sp" tools:ignore="SelectableText" /> </RelativeLayout>
Adapter .java file:
public class ListAdapter extends ArrayAdapter<String> { private Context context; private String[] dataset1; private int[] dataset2; public ListAdapter(Context context,String[] ListArray1, int[] ListArray2) { super(context,R.layout.list_adapter_layout,ListArray); this.context = context; this.dataset1= ListArray1; this.dataset2= ListArray2; } public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = ((Activity)context).getLayoutInflater();
Then I set the item listener element as a list in the form:
listView = (ListView) findViewById(R.id.listview); listView.setOnItemClickListener(this); ListAdapter adapter = new ListAdapter(this,list1,list2); listView.setAdapter(adapter);
Then I used onItemClickListener for the click element:
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { name = (String) arg0.getItemAtPosition(position); }
Here I get the value of the first text view of the user list. But I also want the meaning of the second text view. and if I add more, then how to get the values โโof this.
Please suggest me a way to do this.