mercredi 5 avril 2017

How to return class name from a method ? Also how to find Class of an given object?

I am trying to return a .class file or Activity name from a method of a class. So that i can call that Activity in Intent method. It is like :-

public class MonthCall {
    public Class getobj(View v)
    {
        Class c;
        if(v.getId()== R.id.btnjan)
        {
            c = Jan.class;
        }
        else if(v.getId()== R.id.btnfeb)
        {
            c = Feb.class;
        }
        else
        {
            c = Diary.class;
        }
        return c;
    } 

Now, I want to use these returned value for calling activities as Many of buttons are common in various Activity, so that it will be calling the same Activity.

    public class Month extends Activity {
        MonthCall monthCall;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.month);
        }
        public void monthclick(View view)
        {
            Class cr;
            cr = monthCall.getobj(view);
            Intent i = new Intent(this,cr.getClass());
            startActivity(i);
        }
    }

How can I implement above in right way? Help me to get the solution soon?





Aucun commentaire:

Enregistrer un commentaire