views:

442

answers:

1

Hi,

i have a custom adapter for an arraylist.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:orientation="horizontal">   

 <ProgressBar android:id="@+id/downloadprogress"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="200dip"
    android:layout_height="wrap_content"
    android:max="100"
    android:progress="50"
    android:secondaryProgress="75" />
 <TextView android:id="@+id/tripsname"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>


</LinearLayout>

but when i try to access to the progress bar in the adapter

  private class MyAdapter extends ArrayAdapter<Trip> {

    int resource; 
    public MyAdapter(Context context, int resource, ArrayList<Trip> items) { 
        super(context, resource,items); 
        this.resource=resource; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
        LinearLayout tripListItemView; 
        final Trip t = getItem(position); 
        String name = t.getName();
        boolean offline = t.isOffline() ;
        if(convertView==null) { 
            tripListItemView = new LinearLayout(getContext()); 
            String inflater = Context.LAYOUT_INFLATER_SERVICE; 
            LayoutInflater vi; 
            vi = (LayoutInflater)getContext().getSystemService(inflater); 
            vi.inflate(resource, tripListItemView, true); 
        } 
        else { 
            tripListItemView = (LinearLayout) convertView; 
        } 
        setProgressBarVisibility(true);
        View v = findViewById(R.id.downloadprogress);
        ProgressBar progressHorizontal = (ProgressBar) findViewById(R.id.downloadprogress);

it always return null, like it doesn't find the progress bar. However, the progress bar is shown in the list, but i need to access to it inside the adapter.

Anybody knows the solution?

Thanks

+2  A: 

The strange thing in your code is that findViewById() isn't accessible under ArrayAdapter... I don't understand how your code can compile...

By the way, you should use the view passed in the parameters of getView(...) to retrieve your progress bar.

ProgessBar progressBar = (ProgressBar) convertView.findViewById( R.id.downloadprogressbar );
kosokund
but in my case i should use triplistview, but the answer is correct. thanks!!
xger86x