1

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>

しかし、アダプターの進行状況バーにアクセスしようとすると

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

プログレスバーが見つからないように、常にnullを返します。ただし、プログレスバーはリストに表示されますが、アダプター内でアクセスする必要があります。

誰かが解決策を知っていますか?

ありがとう

4

1 に答える 1

2

あなたのコードの奇妙な点は、findViewById()以下ではアクセスできArrayAdapterないことです...あなたのコードがどのようにコンパイルされるのかわかりません...

ところで、getView(...)進行状況バーを取得するには、のパラメーターで渡されたビューを使用する必要があります。

ProgessBar progressBar = (ProgressBar) convertView.findViewById( R.id.downloadprogressbar );
于 2010-02-25T11:16:18.353 に答える