Reputation: 1033
public class ListDetails extends ListActivity
{
ImageButton imagebutton;
LoanDetails details;
ArrayList<String> CreateReqID1, OpenTime1, RequestSummary1, RequestStatus1;
TextView CreateReqID, OpenTime, RequestSummary, RequestStatus;
ListView list;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.listdetails);
CreateReqID1 = (ArrayList<String>) getIntent().getExtras().get("details1");
OpenTime1 = (ArrayList<String>) getIntent().getExtras().get("details2");
RequestSummary1 = (ArrayList<String>) getIntent().getExtras().get("details3");
RequestStatus1 = (ArrayList<String>) getIntent().getExtras().get("details4");
setListAdapter(new MyAdapter(this, R.layout.requestlistview));
}
private class MyAdapter extends ArrayAdapter<String> {
public MyAdapter(Context context, int resource) {
super(context, resource);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View row = inflater.inflate(R.layout.requestlistview, parent, false);
Log.i("values set", "success");
CreateReqID = (TextView) row.findViewById(R.id.createReq);
OpenTime = (TextView) row.findViewById(R.id.openTime);
RequestSummary = (TextView) row.findViewById(R.id.requestSumary);
RequestStatus = (TextView) row.findViewById(R.id.status);
CreateReqID.setText(CreateReqID1.get(position));
OpenTime.setText(OpenTime1.get(position));
RequestSummary.setText(RequestSummary1.get(position));
RequestStatus.setText(RequestStatus1.get(position));
return row;
}
}
}
I have the above code to add data's into listview but my getview method is not getting called please tell me why.
my listview xml is shown below
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/imageView2"
android:layout_alignRight="@+id/imageButton5"
android:layout_below="@+id/textView1" >
and my list layout format is shown below
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFFFF" >
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView2"
android:layout_marginTop="12dp"
android:layout_x="10dp"
android:layout_y="60dp"
android:text="RequestSummary"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textColorLink="#000000" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView4"
android:layout_marginTop="11dp"
android:layout_x="10dp"
android:layout_y="85dp"
android:text="RequestStatus"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textColorHint="#000000" />
<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:layout_marginTop="11dp"
android:layout_x="10dp"
android:layout_y="35dp"
android:text="OpenTime"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:layout_x="10dp"
android:layout_y="10dp"
android:text="CreateReqID"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />
<TextView
android:id="@+id/createReq"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView2"
android:layout_marginLeft="29dp"
android:layout_toRightOf="@+id/textView4"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textColorHint="#000000" />
<TextView
android:id="@+id/requestSumary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView4"
android:layout_alignBottom="@+id/textView4"
android:layout_alignLeft="@+id/createReq"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />
<TextView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView3"
android:layout_alignBottom="@+id/textView3"
android:layout_alignLeft="@+id/requestSumary"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />
<TextView
android:id="@+id/openTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_alignLeft="@+id/createReq"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />
</RelativeLayout>
I want to populate the textviews dynamically i got everything in the arraylist but my getView method is not getting called.
Upvotes: 1
Views: 146
Reputation: 15477
You missed the getCount()
method of adatper.Just override the getCount method and return appropriate count.Following method will force your getView to be called 5 times
@Override
public synchronized int getCount() {
return 5;
}
Upvotes: 1
Reputation: 7435
you are not passing the array of string to the ArrayAdapter
.. ArrayAdapter
use the passed list to calculate the number of item to display in the view..
Check out the javadoc for ArrayAdapter. You either need to send the array of object to its constructor or call one of the add() method to add the object to the Adapter..
Upvotes: 1