I have implemented single click listener for different text view in sherlock fragment Here is my code
getView().findViewById(R.id.tv_plan).setOnClickListener(btn1Listener);
getView().findViewById(R.id.tv_plan1).setOnClickListener(btn1Listener);
and my listener code
private View.OnClickListener btn1Listener = new View.OnClickListener() {
@Override
public void onClick(View v)
{
android.support.v4.app.FragmentManager fm = getActivity().getSupportFragmentManager();
String title=null;
String tag=null;
switch(v.getId())
{
case R.id.tv_plan:
System.out.println("Plan ids" +v.getId());
title= "My Plan"; tag = "viewplan_dialog";
Utilsdialog dialog_vwplan = new Utilsdialog(context, R.layout.child,title, tag);
System.out.println("Before showing dialog tag");
dialog_vwplan.show(fm, tag);
System.out.println("SUCCESS");
break;
case R.id.tv_plan1:
System.out.println("Plan ids" +v.getId());
title= "Change plan"; tag = "changeplan_dialog";
Utilsdialog dialog_chgplan = new Utilsdialog(context, R.layout.child,title, tag);
dialog_chgplan.show(fm, tag);
break;
}
}
};
My code always calls the last specified listener that is the tv_plan1 listener but i need to provide onclick listener for both text views. My current code call tv_plan1 for both text view clicks....pls help
try this, use Button instead of TextView.
First implements your activity OnClickListener.
public class Auctions extends Activity implements OnClickListener {
private Button menu_Btn;
private Button deal_Btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.xml);
menu_Btn = (Button) findViewById(R.id.menu);
deal_Btn = (Button) findViewById(R.id.deals);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.menu:{
System.out.println("Plan ids" +v.getId());
title= "My Plan"; tag = "viewplan_dialog";
Utilsdialog dialog_vwplan = new Utilsdialog(context, R.layout.child,title, tag);
System.out.println("Before showing dialog tag");
dialog_vwplan.show(fm, tag);
System.out.println("SUCCESS");
break;
}
case R.id.deals:{
System.out.println("Plan ids" +v.getId());
title= "Change plan"; tag = "changeplan_dialog";
Utilsdialog dialog_chgplan = new Utilsdialog(context, R.layout.child,title, tag);
dialog_chgplan.show(fm, tag);
break;
}
default:
break;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With