在我的應用程序我有列表視圖切換按鈕和textview.Here我要在列表上執行兩個操作。列表視圖和切換按鈕在android
1)點擊切換按鈕。 2)點擊列表查看項目。 這兩個工作都很好,但當我點擊切換按鈕時,我根據開啓,關閉條件執行操作。但條件不正常。每次顯示關閉狀態。 下面的代碼是波紋管
public View getView(final int position, View convertView,
ViewGroup parent) {
View v = null;
TextView arryText;
SharedPreferences sh = MainActivity.this.getSharedPreferences(
"onOrOff", MODE_WORLD_READABLE);
Boolean[] onOff = new Boolean[] { sh.getBoolean("SUNDAY", false),
sh.getBoolean("MONDAY", false),
sh.getBoolean("TUESDAY", false),
sh.getBoolean("WEDNESDAY", true),
sh.getBoolean("THURSDAY", false),
sh.getBoolean("FRIDAY", true),
sh.getBoolean("SATURDAY", false) };
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.inflate, null);
arryText = (TextView) v.findViewById(R.id.inflateText);
togg = (ToggleButton) v.findViewById(R.id.toggleButton1);
togg.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (togg.isChecked()) {
Toast.makeText(MainActivity.this, "ison",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "isoff",
Toast.LENGTH_SHORT).show();
}
}
});
arryText.setText(days[position]);
}
return v;
}
每次我「已關閉」任何一個可以幫助我
請檢查此鏈接。我認爲你應該在這裏找到解決辦法。 http://wptrafficanalyzer.in/blog/enabling-multi-selection-mode-in-listview-by-adding-togglebutton-using-custom-layout-in-android/ –