in my application i have list view with toggle button and textview.Here i am going to perform two actions on the list.
1)click on the toggle button.
2)clicking on the list view item.
both working nice but when i click on the toggle button i performed action based upon the on ,off conditions .But the conditions not working properly.every time it shows off condition.
the following code is bellow
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;
}
every time i get “is off ” can any one help me
All compund buttons (in particular ToggleButton) has it’s listener OnCheckedChangedListener, try to override it with togg.setOnCheckedChangedListener() method