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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to