This is not the typical Android workflow, so I highly recommend you don't
do this...  But, if you are dead set on this kind of behavior, do the
following:

   1. Put all your main views you want in either a ViewFlipper (or
   ViewSwitcher if there are only 2)
   2. After calling setContentView, get a reference to the main views by
   calling findViewById
   3. When the back button is pressed check the current view of the
   ViewFlipper or ViewSwitcher against the references you saved in step 2


Thanks,
Justin Anderson
MagouyaWare Developer
http://sites.google.com/site/magouyaware


On Tue, May 15, 2012 at 4:05 AM, Narendra Singh Rathore <
nsr.curi...@gmail.com> wrote:

> Hi all,
> Is this possible to check the current contentView?
>
> As in my code, I am using a single activity, along with three different
> content views (using setContentView()), which I am changing according to my
> requirement.
> All is working fine till now.
>
> Now, what I want is that - when *clicking the back button, I want to
> check the current view (content view)*, and proceed further depending on
> the view.
>
> How can I achieve this if it is possible?
>
>
> Here is my java code, as follows:
>
>
>
> package com.test;
>
>
> import android.app.Activity;
> import android.os.Bundle;
> import android.util.Log;
> import android.view.View;
> import android.view.View.OnClickListener;
> import android.widget.AdapterView;
> import android.widget.AdapterView.OnItemClickListener;
> import android.widget.ArrayAdapter;
> import android.widget.Button;
> import android.widget.ListView;
>
> public class Test_appActivity extends Activity implements OnClickListener,
> OnItemClickListener{
>     /** Called when the activity is first created. */
>     ListView lv;
>     Button btn1,btn2;
>     String[] str=new String[]{"one","two"};
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>        first_view();
>
>     }
>
>     public void first_view()
>     {
>          setContentView(R.layout.main);
>          lv=(ListView)findViewById(android.R.id.list);
>          lv.setTextFilterEnabled(true);
>          ArrayAdapter<String> adapter= new
> ArrayAdapter<String>(getApplicationContext(),
> android.R.layout.simple_list_item_1,str);
>     lv.setAdapter(adapter);
>     lv.setOnItemClickListener(this);
>     }
>
>     public void onClick(View v) {
>     first_view();
>
>     }
>
> //    @Override
> //    public void onBackPressed() {
> //
> if(findViewById(android.R.id.content).equals((View)this.findViewById(R.layout.one))
> //||
> findViewById(android.R.id.content).equals((View)this.findViewById(R.layout.two)))
>
> //        {
> //            first_view();
> //        }
> //        else
> //        {    super.onBackPressed();
> //        }
> //    }
>
>     public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long
> arg3) {
>
>         if(arg2==0)
>         {
>             setContentView(R.layout.one);
>             btn1=(Button)findViewById(R.id.btn);
>             btn1.setOnClickListener(Test_appActivity.this);
>         }
>             else
>             {
>             setContentView(R.layout.two);
>         btn2=(Button)findViewById(R.id.btn1);
>         btn2.setOnClickListener(Test_appActivity.this);
>             }
>     }
>
>
> }
>
>
> Please, help me out in this.
>
> With Regards,
> Narendra
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to