Reputation: 100
I have a button and when I click that button my first custom grid view pops up as dialogue. When I click an item my second custom grid view pops up dismissing my first custom grid view. Now the problem is here, when I click an item in my second custom grid view nothing happens. My setOnItemClickListener()
is not working there.I couldn't able to trace my problem where I have done wrong.
Showing my first grid view `
public void outletList() {
dialogOutlet = new Dialog(SelectCategory.this);
dialogOutlet.setContentView(R.layout.outlet_dialogue_grid);
dialogOutlet.setTitle("Select Outlet");
final GridView lv = (GridView) dialogOutlet.findViewById(R.id.gridOutletView);
oa = new OutletAdapter(this, ParseData.OutletList);
lv.setAdapter(oa);
outletFlag = 1;
lv.setOnItemClickListener(this);
dialogOutlet.show();
dialogOutlet.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
// TODO Auto-generated method stub
outletFlag = 0;
}
});
}`
Showing second grid view `
public void billList() {
dialogueBill = new Dialog(SelectCategory.this);
dialogueBill.setContentView(R.layout.bill_dialogue_grid);
dialogueBill.setTitle("Select Bill");
final GridView bv = (GridView) dialogueBill.findViewById(R.id.gridBillView);
ba = new BillAdapter(this, ParseData.BillList);
bv.findFocus();
bv.setAdapter(ba);
bv.setFocusableInTouchMode(true);
bv.requestFocus();
bv.setClickable(true);
bv.setFocusable(true);
System.out.println("focusable "+bv.isFocusableInTouchMode());
System.out.println("focusable "+bv.findFocus());
System.out.println("Outlet Flag Bill List>>>>>>"+outletFlag);
bv.setOnItemClickListener(this);
dialogueBill.show();
dialogueBill.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
// TODO Auto-generated method stub
outletFlag = 0;
}
});
}`
On Item Click
public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
System.out.println("Outlet Flag inside Item Click>>>>>>"+outletFlag);
if(outletFlag!=1){
HashMap<String, String> out = BillAdapter.billData.get(pos);
String sel_bill = out.get(ParseData.KEY_BILL_NO);
System.out.println("Selected Bill>>>>>>"+sel_bill);
selected_bill = sel_bill;
Intent iii = new Intent(SelectCategory.this, FBHome.class);
startActivity(iii);
}
else{
HashMap<String, String> out = OutletAdapter.outletData.get(pos);
String sel_name = out.get(ParseData.KEY_NAME);
String sel_code = out.get(ParseData.KEY_CODE);
out_pos = pos;
selected_outlet = sel_code;
selected_outlet_name = sel_name;
dialogOutlet.dismiss();
outletFlag = 0;
new GetBillDetails().execute();
}
}
Thanks in advance :)
Upvotes: 0
Views: 1073
Reputation: 4586
In your Gridview Layout if you are using Clickable Widgets like Button or an ImageButton Change it and try.
That is android does not recognize click events inside the Gridadpater views, so if you change that everything should work fine
You could try
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@android:color/darker_gray"
android:layout_width="90dp"
android:layout_height="90dp"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/bt_grid"
android:layout_width="wrap_content"
android:textColor="@android:color/white"
android:layout_height="wrap_content" />
</LinearLayout>
Upvotes: 3
Reputation: 12953
Try using Alert Dialog
private void showGridDialog() {
// Prepare grid view
final GridView bv = (GridView)
dialogueBill.findViewById(R.id.gridBillView);
ba = new BillAdapter(this, ParseData.BillList);
bv.findFocus();
bv.setAdapter(ba);
bv.setFocusableInTouchMode(true);
bv.requestFocus();
bv.setClickable(true);
bv.setFocusable(true);
bv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// do something here
}
});
// Set grid view to alertDialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(bv);
builder.setTitle("Goto");
builder.show();
}
Upvotes: 0