我有一個自定義列表視圖,它有2個textviews和2個按鈕(播放和刪除按鈕) 我想要當我點擊刪除按鈕刪除當前行。從按鈕點擊自定義列表視圖中刪除項目
我的適配器類
import java.util.ArrayList;
import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
public class SunetePreferateAdaptor extends BaseAdapter {
class ob {
String titlu, descriere;
public ob(String titlu, String descriere) {
this.titlu = titlu;
this.descriere = descriere;
}
}
ArrayList<ob> lista;
Context context;
public SunetePreferateAdaptor(Context context) {
this.context = context;
lista = new ArrayList<ob>();
for (int i = 1; i <= 20; i++) {
lista.add(new ob("text", "text2"));
}
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return lista.size();
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return lista.get(arg0);
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.single_favsound_row, arg2, false);
Button b2 = (Button) row.findViewById(R.id.button2);
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// here, i want to delete the current row of the listview
//
//
}
});
TextView titlu = (TextView) row.findViewById(R.id.singleText2);
titlu.setText(lista.get(arg0).titlu);
titlu.setTextColor(Color.WHITE);
titlu.setTypeface(Global.font1);
TextView descriere = (TextView) row.findViewById(R.id.singleText1);
descriere.setText(lista.get(arg0).descriere);
descriere.setTextColor(Color.WHITE);
descriere.setTypeface(Global.font1);
return row;
}
}
嗯,我該怎麼辦呢? 我試着讓ArrayList的靜態和刪除點擊它的項目..但沒有成功..
SunetePreferateAdaptor.this.notifyDataSetChanged();取得了訣竅 – Roisgoen
使用此唯一的第一項是刪除不具體的項目。 – NagarjunaReddy
@NagarjunaReddy然後你沒有做正確 – Raghunandan