0

我正在开发一个 Android 应用程序。在该应用程序中,我设置了一个列表视图,每个视图都有一个 Imageview、Progressbar(InVisible) 和两个按钮。

plAdapter = new PlayAdapter();
         lv1.setAdapter(plAdapter); 
}

private static class AccessoriesViewHolder {
Button play,download;
ProgressBar pb;

}

private class PlayAdapter extends BaseAdapter {

    @Override
    public int getCount() {
        return contactList.toArray().length;
    }

    @Override
    public String getItem(int position) {
        return a;
        //return al[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {


         holder = null;

        if (convertView == null) {
            convertView = getLayoutInflater().inflate(R.layout.design, parent, false);

            holder = new AccessoriesViewHolder();
            holder.play = (Button) convertView.findViewById(R.id.btn_play);
            holder.download = (Button) convertView.findViewById(R.id.btn_dwnld);

            ((Button) convertView.findViewById(R.id.btn_play)).setOnClickListener(mBuyButtonClickListener);
            ((Button) convertView.findViewById(R.id.btn_dwnld)).setOnClickListener(mBuyButtonClickListener);
           ((ProgressBar) convertView.findViewById(R.id.progress_bar)).setVisibility(View.INVISIBLE);

           // convertView.setTag(holder);
        } else 

        {

            holder = (AccessoriesViewHolder) convertView.getTag();
        }


        /*
         * The Android API provides the OnCheckedChangeListener interface
         * and its onCheckedChanged(CompoundButton buttonView, boolean
         * isChecked) method. Unfortunately, this implementation suffers
         * from a big problem: you can't determine whether the checking
         * state changed from code or because of a user action. As a result
         * the only way we have is to prevent the CheckBox from callbacking
         * our listener by temporary removing the listener.
         */


        return convertView;
    }
}

/**
 * Quickly shows a message to the user using a {@link Toast}.
 * 
 * @param message The message to show
 */
private void showMessage(String message) {
    Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
}

private OnClickListener mBuyButtonClickListener = new OnClickListener() {
    @Override
    public void onClick(View v) {
        final int position = lv1.getPositionForView(v);

        // int dummy=position;
            showMessage(listsong[position].toString()+"");


            ((ProgressBar) convertView.findViewById(R.id.progress_bar)).setVisibility(View.INVISIBLE);

    }
};

protected AdapterView<ListAdapter> getListView() 
{
    // TODO Auto-generated method stub
    return null;
}

}

如果我连续单击其中一个 Button ,则进度条必须在该行中可见。

问题是,如果我单击一个按钮,其他行上的进度条会变得可见但不对应的行。

4

2 回答 2

0

只需在 ListView 适配器的 getView() 方法中为按钮添加 OnClickListener 并在 OnClickListener 内设置 ProgressBar 的可见性

于 2013-04-04T07:08:59.753 回答
0

尝试getView像这样更改您的方法:

@Override
public View getView(int position, View convertView, ViewGroup parent) {


     holder = new AccessoriesViewHolder();

     convertView = getLayoutInflater().inflate(R.layout.design, parent, false);

     holder.play = (Button) convertView.findViewById(R.id.btn_play);
     holder.download = (Button) convertView.findViewById(R.id.btn_dwnld);

     ((Button) convertView.findViewById(R.id.btn_play)).setOnClickListener(mBuyButtonClickListener);
     ((Button) convertView.findViewById(R.id.btn_dwnld)).setOnClickListener(mBuyButtonClickListener);
     ((ProgressBar) convertView.findViewById(R.id.progress_bar)).setVisibility(View.INVISIBLE);

     return convertView;
}
于 2013-04-04T07:10:43.777 回答