我正在開發一個Android應用程序。在那個應用程序中,我設置了一個列表視圖,每個列表視圖都有一個Imageview,Progressbar(InVisible)和兩個按鈕。Android -Stuck with ListView項目
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;
}
}
如果我單擊某一行中的某個按鈕,進度欄必須在該行中可見。
問題是,如果我點擊一個按鈕,其他行上的進度條可見但不對應的行。
Rakesh,你必須修改getView的邏輯。創建布爾數組作爲數據,點擊時的OnClickListener獲取索引在列表項上完成,如果該佈局數組中的元素編號設置爲true,將顯示getViewMethod進度條。 – 2013-04-04 07:20:30