Skip to content Skip to sidebar Skip to footer

Creating A List Of Textview's In Android

I am trying to create a list of TextView's in my Android app of name's and organizations. However, the whole list is the same, for example: Joe's work for Construction Co. 15hrs o

Solution 1:

use your getView like this

public View getView(int position, View convertView, ViewGroup parent) {
    Viewv= convertView;
    if (v == null) {
        LayoutInflatervi= (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.row, null);
    }

        TextViewtt= (TextView) v.findViewById(R.id.toptext);
        TextViewbt= (TextView) v.findViewById(R.id.bottomtext);
        // get the 'id' for position.intid= items.get(position);
        if (tt != null) {
              tt.setText(ido.getName(id) + "'s work for " + ido.getOrganization(id));
        }
        if(bt != null){
              bt.setText( ido.totalWorked(id) + "hrs of " + ido.estimatedHours(id) + "hrs");
        }

    return v;
}

Solution 2:

I would try changing

TextViewtt= (TextView) v.findViewById(R.id.toptext);

to

TextViewtt=newTextView(this);
CharSequencetext= ((TextView)v.findViewById(R.id.toptext)).getText();
tt.setText(text);

This will instantiate a new TextView with the same contents, which I think is what you're saying the underlying problem is.

Hope that helps!

Post a Comment for "Creating A List Of Textview's In Android"