Skip to content Skip to sidebar Skip to footer

Custom Simpleadapter Only Shows Sample Text Android

Before making my own SimpleAdapter object because I wanted to change the color of the rows, I was just using new SimpleAdapter(...). Now that I am using my own custom SimpleAdapter

Solution 1:

If it worked previously with just using new SimpleAdapter(...) then in your getView(...) implementation change the first line to this:

Viewrow=super.getView(position, convertView, parent);

And see if that is what you're expecting. Take out the LayoutInflater stuff too.

Solution 2:

In getView(), about where you are setting the row background, you should also set the text for the TextView.

Calling notifyDataSetChanged(), doesn't automagically set your texts right, it just causes the ListView to redraw the visible rows with the new data...practically calling getView() for each row that needs a refresh.

I also suggest setting the background color from the mylistlayout.xml file, and if the getView() function starts taking on a few findViewByID's, you should also consider using a "view holder" approach like in this sample: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html

Solution 3:

You need to set the text in getView(). Like this:

public View getView(int position, View convertView, ViewGroup parent){

    TextView text;

    if (convertView == null) {
        LayoutInflater mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = mInflater.inflate(R.layout.mylistlayout, parent, false);
        text = (TextView) convertView.findViewById(R.id.more_list_text);
    }
    convertView.setBackgroundColor(0xFF0000FF);
    text.setText(map.get(position));
    return convertView;
}

Also, and this is VERY important - store you map as a member variable of the SimpleAdapter ie, put this line at the top of your object definition:

HashMap<String, String> map = newHashMap<String, String>();

Post a Comment for "Custom Simpleadapter Only Shows Sample Text Android"