Пользовательский адаптер Android с линейкой Progress - PullRequest
1 голос
/ 25 февраля 2010

У меня есть специальный адаптер для массива.

<?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>

но когда я пытаюсь получить доступ к индикатору выполнения в адаптере

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

он всегда возвращает ноль, как будто он не находит индикатор выполнения. Тем не менее, индикатор выполнения отображается в списке, но мне нужен доступ к нему внутри адаптера.

Кто-нибудь знает решение?

Спасибо

1 Ответ

2 голосов
/ 25 февраля 2010

Странная вещь в вашем коде в том, что findViewById() недоступен в ArrayAdapter ... Я не понимаю, как ваш код может компилироваться ...

Кстати, вы должны использовать представление, переданное в параметрах getView(...), чтобы получить индикатор выполнения.

ProgessBar progressBar = (ProgressBar) convertView.findViewById( R.id.downloadprogressbar );
...