开发者

Android Custom Adapter with Bar Progress

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();
        开发者_JAVA技巧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


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 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜