Android listview - text custom listview

Bin ich eine Anwendung entwickeln, in das ich eine benutzerdefinierte Liste anzeigen als:

In der Liste anzeigen-xml-code :

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

Dem adapter xml :

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

Den .java-Datei des Adapters :

public class ListAdapter extends ArrayAdapter<String> {
/** Global declaration of variables. As there scope lies in whole class. */
private Context context;
private String[] dataset1;  
private int[] dataset2;

    /** Constructor Class */
    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;
    }

    /** Implement getView method for customizing row of list view. */
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        //Creating a view of row.
        View rowView = inflater.inflate(R.layout.list_adapter_layout, parent, false);   

        TextView tv1 = (TextView)rowView.findViewById(R.id.textview1);      
        TextView tv2 = (TextView)rowView.findViewById(R.id.textview2);

        tv1.setText(data1[position]);       
        tv2.setText(""+data2[position]);

        return rowView;
    }
}

Dann setze ich auf den Artikel Klick-listener auf Liste anzeigen als :

listView = (ListView) findViewById(R.id.listview);
listView.setOnItemClickListener(this);    

ListAdapter adapter = new ListAdapter(this,list1,list2);
listView.setAdapter(adapter);

Dann habe ich onItemClickListener auf Element klicken :

public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
name = (String) arg0.getItemAtPosition(position);       
}

Hier bin ich immer den Wert der ersten text-Ansicht von custom listview. Aber ich möchte auch den Wert des zweiten text-Ansicht. und wenn ich dann, wie man Werte.

Bitte schlagen Sie mich die Art und Weise, das zu tun.

wenn einige der Antworten, die geholfen haben, bitte akzeptieren Sie damit diese Frage nicht als unbeantwortet.
finden Sie mehrere Möglichkeiten, um die getText-der listView - stackoverflow.com/a/28479593/3496570

InformationsquelleAutor Manoj Fegde | 2013-03-20

Schreibe einen Kommentar