Go back to previous activity in click into DrawerLayout? - android

I have a action bar.
When I click the home button in the action bar it shows me a list.
the first problem:
When the draw layout is empty .
And home user clicks the button , a blank page is displayed from right to left .
If the user clicks the back button phone , draw layout disappear ,
Back to main page .
But when i put a list view into draw layout:
After the home user clicks the button , a list is displayed
When the user clicks the back button phone , this time not due to homepage
And the program exits . Main activity is killed .
second problem:
When I click on one of the list items (settings) inside the ACTIVITY SETTING:
My problem is when the user clicks the OK button after setting, the program exits
(doesn't go back Main.Activity).
My English is not good.sorry
Java code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDrawerList = (ListView) findViewById(R.id.right_drawer);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
ListView list=(ListView)findViewById(R.id.list_qustion);
ActionBar mActionBar = getActionBar();
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.custom_action_bar, null);
ImageButton imag_home = (ImageButton) mCustomView
.findViewById(R.id.image_home);
imag_home.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
mDrawerLayout.closeDrawer(mDrawerList);
} else {
mDrawerLayout.openDrawer(mDrawerList);
}
}
});
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
Myadapter2 adapter2=new Myadapter2(getBaseContext(), title, draw);
mDrawerList.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
switch(position)
{
case 0:
{
Intent x2=new Intent(MainActivity.this,LoveActivity.class);
startActivity(x2);
break;
}
case 1:
{
Intent x=new Intent(MainActivity.this,SettingActivity.class);
x.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(x, request_Code);
}
//............
}
}
});
mDrawerList.setAdapter(adapter2);
//list view into draw layout
Myadapter adapter=new Myadapter(getBaseContext());
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
switch(position)
{
case 0:
//......
}
}
});
list.setAdapter(adapter);
//main list view
}
I have a class Myadapte2 like class Myadapter in package
SettingActivity:
Button ok=(Button)findViewById(R.id.button_ok);
Button cancell=(Button)findViewById(R.id.button_no);
ok.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent returnIntent=new Intent();
setResult(RESULT_OK,returnIntent);
finish();
}
});
cancell.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
activity_main :
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:orientation="horizontal"
android:background="#82c6fb"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="1dp"
android:gravity="center"
>
<ListView
android:id="#+id/list_qustion"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="2dp"/>
</LinearLayout>
<ListView
android:id="#+id/right_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#eaeaea"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"/>
</android.support.v4.widget.DrawerLayout>

Related

Android Navigation Drawer not adding ActionBar menu button

My program currently allows me to open the navigation bar by sliding my finger but will not display a menu button so i can click the menu button to open it. I have the onPostCreate and onOptionsItem Overide functions but I do not believe they are ever called. How do I fix this problem.
My programs minimum API level is 8 so I don't know if that is a problem.Thank you!
Main Activity:
public class Home_Page extends ActionBarActivity implements AdapterView.OnItemClickListener{
NavigationDrawer drawerLayout;
ListView listViewLeft, listViewRight;
String selectedMenuItem;
MyListViewAdapter myListViewAdapter;
int[] images = {R.drawable.menu_icon, R.drawable.menu_icon, R.drawable.menu_icon, R.drawable.menu_icon};
String[] listViewLeftItems = {"Home", "Choice 2", "Choice 3", "Choice 4"};
Intent intent;
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home__page);
drawerLayout = new NavigationDrawer(this, (DrawerLayout) findViewById(R.id.drawerLayout), getSupportActionBar());
drawerLayout.createDrawer();
initializeVar();
myListViewAdapter = new MyListViewAdapter(this, images, listViewLeftItems);
listViewLeft.setAdapter(myListViewAdapter);
listViewLeft.setOnItemClickListener(this);
}
public void initializeVar(){
listViewLeft = (ListView) findViewById(R.id.drawerListLeft);
listViewRight = (ListView) findViewById(R.id.drawerListRight);
}
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
drawerLayout.closeDrawers();
switch(position){
case 0:
selectListViewItemLeft(position);
new Thread() {
public void run() {
try {
intent = new Intent(Home_Page.this, Home_Page.class);
startActivity(intent);
finish();
}catch (Exception e){
e.printStackTrace();
}
}
}.start();
break;
case 1:
selectListViewItemLeft(position);
new Thread() {
public void run() {
try {
Intent intent = new Intent(Home_Page.this, AddAthlete.class);
startActivity(intent);
finish();
}catch (Exception e){
e.printStackTrace();
}
}
}.start();
break;
case 2:
selectListViewItemLeft(position);
break;
case 3:
selectListViewItemLeft(position);
break;
}
}
public void selectListViewItemLeft(int position){
listViewLeft.setItemChecked(position, true);
selectedMenuItem = listViewLeftItems[position];
}
}
Navigation Drawer Class: (Custom class so can create new navigation bar in different activities)
public class NavigationDrawer extends Activity{
DrawerLayout drawerLayout;
ActionBarDrawerToggle drawerToggle;
Activity currentActivity;
android.support.v7.app.ActionBar actionBar;
NavigationDrawer(Context context, DrawerLayout drawerLayout, android.support.v7.app.ActionBar actionBar) {
this.currentActivity = (Activity) context;
this.drawerLayout = drawerLayout;
this.actionBar = actionBar;
}
#TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void createDrawer() {
drawerToggle = new ActionBarDrawerToggle(currentActivity, drawerLayout, R.drawable.menu_icon, R.string.drawer_open, R.string.drawer_closed) {
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
#Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
actionBar.setTitle("Menu");
}
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
#Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
actionBar.setTitle(getTitle());
}
};
drawerLayout.setDrawerListener(drawerToggle);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setIcon(android.R.color.transparent);
actionBar.setHomeButtonEnabled(true);
}
public void closeDrawers(){
drawerLayout.closeDrawers();
}
// Displays toggle button to expand drawer
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
drawerToggle.syncState();
Log.e("", "onPostCreate Run");
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(drawerToggle.onOptionsItemSelected(item)){
Log.e("", "onOptionsItemSelected Run");
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
drawerToggle.onConfigurationChanged(newConfig);
Log.e("", "onConfigurationChanged Run");
}
}
In your activity's layout file, use drawer layout as your parent layout and add toolbar as child view. For ex:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical>
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar"></include>
<!-- Add your Main Content Here -->
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left">
<!-- Add your Drawer layout content here -->
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
And your toolbar layout, tool_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar ` xmlns:android="http://schemas.android.com/apk/res/android"`
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/action_bar_color"
app:theme="#style/ThemeOverlay.AppCompat.ActionBar"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
</android.support.v7.widget.Toolbar>

The method onItemClick in ListView is not working

I tried to implements two navigation drawer on same activity, I am following this post to do it Two Navigation Drawer on same Activity, but when I tried to capture onItemClick in ListView Nothing it happens. Thanks in advance for help.
Below is my code..
MainActivity.java
public class MainActivity extends ActionBarActivity
{
DrawerLayout mDrawerlayout;
ListView mDrawerList_Left,mDrawerList_Right;
ActionBarDrawerToggle mDrawerToggle;
ImageButton imgLeftMenu,imgRightMenu;
NavDrawerAdapter Left_Adapter;
NavDrawerAdapter Right_Adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//===============Initialization of Variables=========================//
mDrawerlayout=(DrawerLayout)findViewById(R.id.drawer_layout);
mDrawerList_Left=(ListView)findViewById(R.id.drawer_list_left);
mDrawerList_Left.setOnItemClickListener(new DrawerItemClickListener());
mDrawerList_Right=(ListView)findViewById(R.id.drawer_list_right);
imgLeftMenu=(ImageButton)findViewById(R.id.imgLeftMenu);
imgRightMenu=(ImageButton)findViewById(R.id.imgRightMenu);
mDrawerlayout.setDrawerListener(mDrawerToggle);
//============== Define a Custom Header for Navigation drawer=================//
LayoutInflater inflator=(LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v=inflator.inflate(R.layout.header, null);
imgLeftMenu=(ImageButton)v.findViewById(R.id.imgLeftMenu);
imgRightMenu=(ImageButton)v.findViewById(R.id.imgRightMenu);
getSupportActionBar().setHomeButtonEnabled(true);
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayUseLogoEnabled(false);
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#1281A9")));
getSupportActionBar().setIcon(
new ColorDrawable(getResources().getColor(android.R.color.transparent)));
getSupportActionBar().setCustomView(v);
imgLeftMenu.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (mDrawerlayout.isDrawerOpen(mDrawerList_Right)){
mDrawerlayout.closeDrawer(mDrawerList_Right);
}
mDrawerlayout.openDrawer(mDrawerList_Left);
mDrawerList_Left.bringToFront();
mDrawerlayout.requestLayout();
}
});
imgRightMenu.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (mDrawerlayout.isDrawerOpen(mDrawerList_Left)){
mDrawerlayout.closeDrawer(mDrawerList_Left);
}
mDrawerlayout.openDrawer(mDrawerList_Right);
mDrawerList_Right.bringToFront();
mDrawerlayout.requestLayout();
}
});
RefreshListView();
}
// Filling the ArrayLists
public void RefreshListView() {
NavDrawerMenuItem[] menu = new NavDrawerMenuItem[]{
NavMenuLabel.create("First Label"),
NavMenuIconLabel.create("First IconLabel", R.drawable.ic_drawer)
};
Left_Adapter = new NavDrawerAdapter(this,R.layout.navdrawer_item,menu);
mDrawerList_Left.setAdapter(Left_Adapter);
Right_Adapter = new NavDrawerAdapter(this,R.layout.navdrawer_item,menu);
mDrawerList_Right.setAdapter(Right_Adapter);
}
private class DrawerItemClickListener implements ListView.OnItemClickListener {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch(position) {
case 1:
Log.d("Item Click","1");
break;
case 2:
Log.d("Item Click","2");
break;
default:
}
}
}
activity_main.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="#+id/drawer_layout"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout android:id="#+id/container" android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="#+id/drawer_list_left"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:divider="#android:color/transparent"
android:layout_marginLeft="-64dp"
android:background="#FFFFFF"/>
<ListView
android:id="#+id/drawer_list_right"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:divider="#android:color/transparent"
android:background="#FFFFFF"/>

How to make an ImageButton clickable and hide the home logo Button in Actionbar in android?

I have added an ImageButton on the Actionbar. I have no idea how to make it clickable. Secondly, I want to hide the home logo button/image from the Actionbar. And finally I want to display a title on the Action Bar. Can anyone suggest me step by step what to do?
My codes are as below:
actionbars.xml
<ImageView
android:id="#+id/actionBarLogo"
android:contentDescription="#string/app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:duplicateParentState="false"
android:focusable="false"
android:longClickable="false"
android:layout_marginLeft="225dp"
android:src="#drawable/settings" />
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(getResources().getDrawable(R.color.blue));
actionBar.setCustomView(R.layout.actionbars);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayUseLogoEnabled(true);
}
public boolean onMenuItemSelected(int featureId, MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
ImageButton b=(ImageButton)findViewById(R.id.actionBarLogo);
b.setOnClickListener(new OnClickListener() {
//#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i=new Intent(MainActivity.this,Lists.class);
startActivity(i);
}
});
return super.onOptionsItemSelected(item);
}
}
If you're going to use a custom View in your ActionBar, you'll need to add it using a different method to make your ImageView clickable. Here's an example of doing that along with hiding the home affordance.
// Initialize your custom layout
final View v = getLayoutInflater().inflate(R.layout.actionbars, null);
final ImageView iv = (ImageView) v.findViewById(R.id.actionBarLogo);
iv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Called when your View is clicked
}
});
// Add the custom View to your ActionBar
final ActionBar actionBar = getActionBar();
actionBar.setCustomView(v);
actionBar.setDisplayShowCustomEnabled(true);
// Remove the "up" affordance
actionBar.setDisplayShowHomeEnabled(false);
Your ImageView isn't a MenuItem, that's why your app force closes in Activity.onOptionsItemSelected.
To set the title, simple add setTitle(titleString); to the onCreate method.
You already made the ImageButton clickable by adding android:clickable="true"
Now you need to get the button and add a click listener:
ImageButton iv = (ImageButton) findViewById(R.id.resourceID);
iv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// code
}
});

Adding a button in an activity within fragments with Actionbarsherlock inside the fragment

So I want to have 3 buttons that always appear throughout fragments. I've got an activity with 3 buttons and a fragment layout that contains a fragment with actionbarsherlock inside. The problem is, the buttons in the activity are not clickable and nothing can be executed in the OnClickListener; but the buttons run just fine if I replace the fragment containing actionbarsherlock with a regular fragment without actionbarsherlock inside. I wonder what's wrong.
Here is my code.
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="2dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<FrameLayout
android:id="#+id/fragment_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/button1" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/fragment_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:text="mission" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_centerHorizontal="true"
android:text="feed" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button2"
android:layout_alignBottom="#+id/button2"
android:layout_alignRight="#+id/fragment_content"
android:text="Profile" />
</RelativeLayout>
MyActivity.java:
public class MyActivity extends SherlockFragmentActivity {
/**
* Called when the activity is first created.
*/
Fragment frg;
ActionBarFragment b;
Button btnmission;
Button btnfeed;
Button btnprofile;
boolean small;
static int previousItem;
int tabname;
private Fragment mVisible = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
previousItem=1;
btnmission = (Button) findViewById(R.id.button1);
btnfeed = (Button) findViewById(R.id.button2);
btnprofile = (Button) findViewById(R.id.button3);
btnmission.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Log.i("clicked", "button");
if(previousItem!=1){
Intent intent=new Intent(getBaseContext(),MyActivity.class);
startActivity(intent);
}
previousItem=1;
}
});
btnfeed.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if(previousItem!=2){
Intent intent=new Intent(getBaseContext(),MissionFragment.class);
intent.putExtra("class", "Feed");
startActivity(intent);
}
previousItem=2;
}
});
btnprofile.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
}
});
private void setupFragments() {
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
frg = (ActionBarFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_content);
if (frg == null) {
frg = new ActionBarFragment();
ft.add(R.id.fragment_content, frg);
}
ft.hide(frg);
ft.commit();
}
private void showFragment(Fragment fragmentIn) {
if (fragmentIn == null) return;
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
if (mVisible != null) ft.hide(mVisible);
ft.show(fragmentIn).commit();
mVisible = fragmentIn;
}
It adds a fragment to the activity and actionbar inside the fragment.
ActionBarFragment.java:
public class ActionBarFragment extends SherlockFragment {
int tabname;
#Override
public void onStart()
{
// TODO Auto-generated method stub
super.onStart();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.empty_view, container, false);
// Getting an instance of action bar
ActionBar actionBar = this.getSherlockActivity().getSupportActionBar();
// Enabling Tab Navigation mode for this action bar
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Enabling Title
actionBar.setDisplayShowTitleEnabled(true);
// Creating Android Tab
Tab tab1 = actionBar.newTab()
.setText("Nova Missoes")
.setTabListener(new CustomTabListener<ListMission>(this.getSherlockActivity(), "mission list", ListMission.class));
// Adding Android Tab to action bar
actionBar.addTab(tab1);
// Creating Apple Tab
Tab tab2 = actionBar.newTab()
.setText("Missoes Concluidas")
.setTabListener(new CustomTabListener<MissionAccomplished>(this.getSherlockActivity(), "mission accomplished", MissionAccomplished.class));
// Adding Apple Tab to action bar
actionBar.addTab(tab2);
Intent in=getSherlockActivity().getIntent();
tabname=in.getIntExtra("tabname", 0);
Log.i("intent", Integer.toString(tabname));
if(tabname==2){
actionBar.selectTab(tab2);
}
// Orientation Change Occurred
if(savedInstanceState!=null){
int currentTabIndex = savedInstanceState.getInt("tab_index");
actionBar.setSelectedNavigationItem(currentTabIndex);
}
return view;
}
#Override
public void onSaveInstanceState(Bundle outState) {
int currentTabIndex = getSherlockActivity().getSupportActionBar().getSelectedNavigationIndex();
outState.putInt("tab_index", currentTabIndex);
super.onSaveInstanceState(outState);
}
}
No problem with displaying the buttons and the tabs, it's just that the OnClickListener is not called when the program runs.

Click event for flipview or swipe view

I'm trying to implement the Click event for fragments that display images or buttons.
I am able to implement the flip view to get another fragment but I am unable get the click event working on such fragments.
I have tried with android:onClick, even setting clickable to true. I even tried with onClickListener and onTouch but it's not firing for me.
This is the code I have tried.
public class MainActivity extends Activity {
private FlipViewGroup contentView;
public int currentimageindex=0;
private GestureDetector mDetector;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
// hde staitbar otef Andoroid
// could also be usdne lar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setTitle(R.string.activity_title);
contentView = new FlipViewGroup(this);
contentView.addFlipView(View.inflate(this, R.layout.second_page, null));
contentView.addFlipView(View.inflate(this, R.layout.first_page, null));
setContentView(contentView);
// setContentView(R.layout.second_page);
contentView.startFlipping(); //make the first_page view flipping
ImageView imgFavorite = (ImageView) findViewById(R.id.imageView1);
imgFavorite.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,
"The favorite list would appear on clicking this icon",
Toast.LENGTH_LONG).show();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
}
#Override
protected void onResume() {
super.onResume();
contentView.onResume();
}
#Override
protected void onPause() {
super.onPause();
contentView.onPause();
}
public void onclick(View v){
ImageView imgFavorite = (ImageView) findViewById(R.id.imageView1);
imgFavorite.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,
"The favorite list would appear on clicking this icon",
Toast.LENGTH_LONG).show();
}
});
}
}
This is my xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#android:color/white">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView5"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:src="#drawable/android"
android:clickable="true"
android:onClick="onclick"/>
</RelativeLayout>
Is there some reason a fragment within a flip view doesn't respond to click or touch events, or is there something I'm doing wrong in my code?
As far as i understand, FlipViewGroup is your custom view group implementation.
If that is the case you need onInterceptTouchEvent() see the sample code here.
http://developer.android.com/training/gestures/viewgroup.html

Categories

Resources