Note that there are some explanatory texts on larger screens.

plurals
  1. POafter override getview method for custom adapter for a listview,see nothing in listview
    text
    copied!<p>I'm new in android programming . I'm writing an android program which has two tabs: detailstab in which user fill a form and hit save button. listtab in which display what user insert in edittexts control in details tab. to implement this i made this classes:</p> <p>detail java class :</p> <pre><code> public class detail { public String name; public String adr; public String note; public int radioValue; } </code></pre> <p>details activity class in which i make an arraylist and add objects from detail:</p> <pre><code>public class details extends Activity { public ArrayList&lt;detail&gt; detaillist=new ArrayList&lt;detail&gt;(); public EditText etName; public EditText etAdr; public EditText etNote; public RadioGroup rg; public RadioButton rb_0; public RadioButton rb_1; public RadioButton rb_2; static details detailsActivity; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); detailsActivity=this; setContentView(R.layout.details_tab); Button btnSave=(Button) findViewById(R.id.button1); //define an arraylist to add detail object to it etName=(EditText) findViewById(R.id.editText1); etAdr=(EditText) findViewById(R.id.editText2); etNote=(EditText) findViewById(R.id.editText3); rg=(RadioGroup) findViewById(R.id.radioGroup1); rb_0=(RadioButton) findViewById(R.id.radio0); rb_1=(RadioButton) findViewById(R.id.radio1); rb_2=(RadioButton) findViewById(R.id.radio2); btnSave.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final detail d=new detail(); makeDetailList(d); } }); } public void clear(EditText et) { et.setText(""); } public ArrayList&lt;detail&gt; makeDetailList(detail d){ d.name=etName.getText().toString(); d.adr=etAdr.getText().toString(); if(rb_0.isSelected()) { d.radioValue=0; } else if (rb_1.isSelected()) { d.radioValue=1; } else if (rb_1.isSelected()) { d.radioValue=2; } detaillist.add(d); return detaillist; } public static details getInstance(){ return detailsActivity; } </code></pre> <p>and finally lists activity class this class contains a listview to display data from details tab:</p> <pre><code> public class list extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_tab); ListView lv=(ListView) findViewById(R.id.listView1); MyAdapter adapter=new MyAdapter(this,android.R.layout.simple_list_item_1 , R.id.textView1, details.getInstance().detaillist); lv.setAdapter(adapter); (this,R.layout.my_list,R.id.textView1,R.id.textView2,)); } private class MyAdapter extends ArrayAdapter&lt;String&gt;{ public MyAdapter(Context context, int resource, int textViewResourceId, ArrayList&lt;detail&gt; detaillist) { super(context, resource, textViewResourceId); } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View row=inflater.inflate(R.layout.my_list, parent,false); ArrayList&lt;detail&gt; items=details.getInstance().detaillist; ImageView ivR=(ImageView) row.findViewById(R.id.imageView1); TextView tvN=(TextView) row.findViewById(R.id.textView1); TextView tvA=(TextView) row.findViewById(R.id.textView2); tvN.setText(items.get(position).name); tvA.setText(items.get(position).adr); if(items.get(position) != null) { if(items.get(position).radioValue==0) { ivR.setImageResource(R.drawable.t); } else if(items.get(position).radioValue==1) { ivR.setImageResource(R.drawable.t); } else if(items.get(position).radioValue==2) { ivR.setImageResource(R.drawable.t); } } return row; } } } </code></pre> <p>and this is my_list.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;ImageView android:id="@+id/imageView1" android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="29dp" android:layout_marginTop="24dp" android:src="@drawable/ic_launcher" /&gt; &lt;TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView1" android:text="TextView" android:textColor="#687EFC" android:textSize="20sp" /&gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/imageView1" android:layout_marginLeft="31dp" android:layout_toRightOf="@+id/imageView1" android:text="TextView" android:textColor="#18277D" android:textSize="30sp" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>I really appreciate your help regards</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload