【发布时间】:2015-06-10 06:46:09
【问题描述】:
我有一个自定义列表视图,所有行都带有切换按钮。我有一个用于 ToggleButton 的 onlick 列表器,我试图将列表视图中所有切换按钮的状态设置为 false,除了我预先设置的那个。我已经在下面发布了适配器的代码。请帮我解决一下这个。
为了更简单,我必须在按下/单击时将 ToggleButton 状态设置为 True,并将所有其他切换按钮状态设置为 False。此外,像一个单选组按钮。请指教。
package Test.in.example.testairlight;
import java.util.ArrayList;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
public class PaAdapter extends ArrayAdapter<PaModel> {
SQLiteDatabase db;
private DBHelper dbH;
private ArrayList<PaModel> objects;
public PaAdapter(Context context, int textViewResourceId, ArrayList<PaModel> objects) {
super(context, textViewResourceId, objects);
this.objects = objects;
}
public View getView(int position, View convertView, ViewGroup parent){
View v = convertView;
final Context cc=parent.getContext();
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.pa_list_item, null);
}
PaModel i = objects.get(position);
if (i != null) {
TextView ttd = (TextView) v.findViewById(R.id.devicelocation);
final TextView mtd = (TextView) v.findViewById(R.id.deviceid);
TextView dzone = (TextView) v.findViewById(R.id.txtzonedetail);
final ToggleButton togglePA = (ToggleButton) v.findViewById(R.id.togglePA);
final ToggleButton toggleAlert = (ToggleButton) v.findViewById(R.id.toggleAlert);
final ToggleButton toggleListen = (ToggleButton) v.findViewById(R.id.toggleListen);
if (ttd != null){
ttd.setText(i.getDevicelocation());
}
if (mtd != null){
mtd.setText(String.valueOf(i.getDeviceid()));
}
toggleListen.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//// Set Everything to OFF State
//// Turn ON only the active Item
}
});
////// Listen Button
if (dzone !=null){
dzone.setText(i.getDevicezonedetail());
}
}
return v;
}
}
【问题讨论】:
-
您想将仅列表项(单击了切换按钮的位置)中的所有按钮设置为 false,还是将列表中的所有按钮设置为 false?
标签: android