特定のボタンをクリックしたときにボタンの画像を変更し、他のすべてのボタンを削除したいのですが、助けてください。
これは私のコードです
public void onClick(View view) {
Object tag = ((Button) view).getTag();
System.out.println("value o ftagagdsgsdg:::" +tag.toString());
String strtag = tag.toString();
System.out.println("value of strtag:::" +strtag);
enablebutton = Integer.valueOf(tag.toString());
System.out.println("value of enable buttons variable::" +enablebutton);
DeselectButtons();
((Button)view).setEnabled(true);
for(int a = 0;a<adapt_obj.city_id_array.length;a++){
System.out.println("ddsgdgsdg::"+adapt_obj.city_code_array[a]);
System.out.println("value o ftagagdsgsdg:inside for loop::" +tag.toString());
if(tag.toString() == adapt_obj.city_code_array[a]){
((Button)view).setFocusable(true);
//clicked = false;
// Calling process to fetch the data of city
selectedcityidclicked(tag.toString(), view);
((Button)view).setSelected(true);
/*Drawable dr = getResources().getDrawable(R.drawable.location_btn_active_1);// active
Bitmap bitmap = ((BitmapDrawable) dr).getBitmap();
// Scale it to 50 x 50
// Set your new, scaled drawable "d"
((Button)view).setBackgroundDrawable(new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, 10, 10, true)));*/
// ((Button)view).invalidate();
}
else if(tag.toString() != adapt_obj.city_code_array[a]){
/*((Button)view).setFocusable(true);
selectedcityidclicked(tag.toString(), view);
Drawable dr2 = getResources().getDrawable(R.drawable.location_btn_active_1);// inactive
Bitmap bitmap2 = ((BitmapDrawable) dr2).getBitmap();
// Scale it to 50 x 50
Drawable d2 = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap2, 10, 10, true));
// Set your new, scaled drawable "d"
((Button)view).setBackgroundDrawable(d2);
((Button)view).invalidate();
clicked = false;*/
}
}
/*else if(tag.toString() != adapt_obj.city_code_array[a]){
((Button)view).setFocusable(true);
Drawable dr2 = getResources().getDrawable(R.drawable.location_btn_inactive_1);//instead of inactive
Bitmap bitmap2 = ((BitmapDrawable) dr2).getBitmap();
// Scale it to 50 x 50
Drawable d2 = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap2, 10, 10, true));
// Set your new, scaled drawable "d"
((Button)view).setBackgroundDrawable(d2);
((Button)view).invalidate();
}
else {
Drawable dr2 = getResources().getDrawable(R.drawable.location_btn_active_1);//white
Bitmap bitmap2 = ((BitmapDrawable) dr2).getBitmap();
// Scale it to 50 x 50
Drawable d2 = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap2, 10, 10, true));
// Set your new, scaled drawable "d"
((Button)view).setBackgroundDrawable(d2);
((Button)view).invalidate();
}*/
/*((Button) view).setText("*");
//selectedcityidclicked(tag.toString());
((Button) view).setEnabled(false);*/
}
private void DeselectButtons() {
// TODO Auto-generated method stub
for(int x=0; x<adapt_obj.city_code_array.length;x++){
System.out.println("value of enable tag::" +enablebutton);
System.out.println("valuie dofdsf xxx:::" +x);
if (enablebutton!= x)
//What should i do here as i had to take the un clicked button as set selected as false //
// ((Button)view).setSelected(false);
//this.findViewById(i).setSelected(false);
//this.findViewById(i).setSelected(false);
}
}
private void selectedcityidclicked(String cityval, View view) {
cityidvalue = "&city_code="+cityval;
System.out.println("value of cityidvalue::" +cityidvalue);
new MyAsyncTask(view).execute();
}