• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Copy content from row in listview

Howdy,

I'm trying to copy the content of a certain row in a listview, so I can change it and later reload that row content.

I've tried defining a new LinearLayout and then getChildAt(), but it's working. Any solution? Is there some sort of clone or copy that I'm missing?

Thanks,
wBishop
 
This is sort of how ListViews work behind the scenes....

You should look for a tutorial on using a BaseAdapter with a listview. getChildAt() can be unreliable....


BaseAdapter has a method you override called getView()

Code:
// in this method, you inflate a new view if convertView == null
// if convertView  is not null, that means Android has 'recycled'
// a view that has gone off screen and is giving it to you to re-use
// this saves CPU and memory since creating/inflating views is an 
// 'expensive' operation
// NOTE: myAppContext is a class variable passed to my Adapter earlier 

@Override
public View getView ( int position, View convertView, ViewGroup parent )
{
    if ( convertView == null  )
    {
         LayoutInflater inflater = (LayoutInflater) myAppContext
         .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         convertView = inflater.inflate(R.layout.my_row_layout, null);
     }


    // here you can do things like reset the text, etc

    TextView textView = (TextView) convertView.findViewById(R.id.text_in_row);

    textView.setText( String.valueOf (position) ); 

    return convertView;
}
 
Back
Top Bottom