am doing an android application, in that am loading check boxes in grid view from JSON web services . Up to this it is working perfectly. when i click the check box for the first time it is not triggering the event. but the second time it is working properly. Please help me if anybody knows
My java Code:
@SuppressWarnings("deprecation")
public void showFolderPopUPforEdit() {
int count = 0;
String folderID = null;
String selectedfolderID = null;
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
editpopupView = layoutInflater.inflate(R.layout.edit_folders, null);
editpopupWindow = new PopupWindow(editpopupView,
LayoutParams.MATCH_PARENT, 1060);
editpopupWindow.showAtLocation(editpopupView, Gravity.BOTTOM, 0, 0);
try {
leadna_leadsFolderjsonaray = leadna_leadFoldersjson
.getJSONArray("folderList");
for (int i = 0; i < leadna_leadsFolderjsonaray.length(); i++) {
cb = new CheckBox(this);
cb.setChecked(false);
cb.setFocusable(false);
cb.setFocusableInTouchMode(false);
cb.setBackground(getResources()
.getDrawable(R.drawable.uncheck1));
cb.setButtonDrawable(android.R.color.transparent);
JSONObject c = leadna_leadsFolderjsonaray.getJSONObject(i);
folderID = c.getString("category_id");
for (int j = 0; j < leadna_leadsSelectedFolderjsonaray.length(); j++) {
JSONObject arr2 = leadna_leadsSelectedFolderjsonaray
.getJSONObject(j);
selectedfolderID = arr2.getString("attach_category");
if (folderID.equalsIgnoreCase(selectedfolderID)) {
cb.setChecked(true);
cb.setBackground(getResources().getDrawable(
R.drawable.check_btn));
cb.setFocusable(false);
cb.setFocusableInTouchMode(false);
cb.setButtonDrawable(android.R.color.transparent);
break;
}
}
cb.setText(c.getString("category_name"));
cb.setTextColor(Color.BLACK);
cb.setTextSize((float) 14);
cb.setTag(c.getString("category_id"));
cb.setLayoutParams(new GridView.LayoutParams(346, 90));
cb.setPadding(54, 0, 0, 0);
cb.setOnClickListener(this);
cb.setId(i);
cb.requestFocus();
meditButtons.add(cb);
}
GridView gridView = (GridView) editpopupView
.findViewById(R.id.gridEditView1);
gridView.setAdapter(new CustomAdapter(this, meditButtons));
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Button btnSaveFolders = (Button) editpopupView
.findViewById(R.id.btnAddActivity);
btnSaveFolders.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
Button btnDismiss = (Button) editpopupView.findViewById(R.id.button6);
btnDismiss.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
editpopupWindow.dismiss();
}
});
}
@Override
public void onClick(View v) {
CheckBox selection = (CheckBox)v;
//selection.setCompoundDrawablesWithIntrinsicBounds(R.drawable.clickfolders,0, 0, 0);
selection.requestFocus();
if (selection.isChecked() == true) {
selection.setBackground(getResources().getDrawable(
R.drawable.uncheck1));
//selection.setButtonDrawable(android.R.color.transparent);
} else {
selection.setBackground(getResources().getDrawable(
R.drawable.check_btn));
//selection.setButtonDrawable(android.R.color.transparent);
}
//Toast.makeText(getBaseContext(), selection.getTag()+ " was pressed!", Toast.LENGTH_SHORT).show();
}
My Layout XML :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_black_transparent_90"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="26dp"
android:layout_marginTop="18dp"
android:text="@string/FOLDERS"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/darker_gray" />
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/textView1"
android:layout_marginRight="39dp"
android:visibility="gone" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_red_edit" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/imageView1"
android:text="EDIT"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/darker_gray"
android:textSize="16dp" />
</RelativeLayout>
<GridView
android:id="@+id/gridEditView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/ddd"
android:layout_below="@+id/textView1"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="@android:color/transparent"
android:horizontalSpacing="1dp"
android:numColumns="2"
android:verticalSpacing="1dp" >
</GridView>
<RelativeLayout
android:id="@+id/ddd"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<Button
android:id="@+id/button6"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:background="@drawable/ic_red_cancel_47"
android:gravity="center"
android:visibility="visible" />
<Button
android:id="@+id/btnAddActivity"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:background="@drawable/ic_red_ok_47" />
</RelativeLayout>
</RelativeLayout>
Aucun commentaire:
Enregistrer un commentaire