I ran up against a few problems when i use Slidingdrawer. How to fix it.
Main XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#color/white">
<SlidingDrawer
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/black"
android:handle="#+id/handle"
android:id="#+id/slideD">
<Button
android:layout_width="60dp"
android:layout_height="60dp"
android:id="#id/handle"
android:background="#drawable/arrow_up"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/ic_launcher"
>
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/ic_launcher"
>
</Button>
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
Activity
public class ATDTActivity extends Activity {
SlidingDrawer slideD;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
slideD = (SlidingDrawer)findViewById(R.id.slideD);
slideD.setOnDrawerOpenListener(new OnDrawerOpenListener(){
#Override
public void onDrawerOpened() {
slideD.getHandle().setBackgroundResource(R.drawable.arrow_down);
}
});
slideD.setOnDrawerCloseListener(new OnDrawerCloseListener(){
#Override
public void onDrawerClosed() {
sideD.getHandle().setBackgroundResource(R.drawable.arrow_up);
}
});
}
}
Thank for help!.
Your post does not have much context to explain the code sections; please explain your scenario more clearly.
Add content to SlidingDrawer:
....
<SlidingDrawer
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:content="#+id/content"
android:handle="#+id/handle"
android:id="#+id/slideD">
........
<LinearLayout
android:id="#id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
.......
Don't even bother with this class.
This class was deprecated in API level 17.
Related
May be it is so easy but do not know i have tried so much but it's not working :(
I have layout like this way
And i have following java code
public class MainActivity extends FragmentActivity{
private ImageView ivMainMenu;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ivMainMenu = (ImageView) findViewById(R.id.ivMainMenu);
ivMainMenu.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("showSlider clicked");
}
});
}
i have tried
android:clickable="true"
but still not working
below is my xml code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rlMainHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/header_bg"
android:orientation="vertical" >
<TextView
android:id="#+id/tvHeaderText"
style="#style/header_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<TextView
android:id="#+id/txtScore"
style="#style/black_large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="#dimen/extra_small"
android:background="#drawable/keyboard_btn"
android:padding="#dimen/extra_small"
android:text="#string/finish"
android:textColor="#color/dark_text_color"
android:textStyle="bold"
android:visibility="gone" />
<ImageView
android:id="#+id/ivMainMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:clickable="true"
android:src="#drawable/menu" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/rlMainHeader"
android:background="#color/main_bg"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/flMain"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<LinearLayout
android:id="#+id/llMainSlider"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:visibility="visible" >
<include
android:layout_width="wrap_content"
android:layout_height="match_parent"
layout="#layout/slider" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/dark_text_color"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</RelativeLayout>
in my logcat i am getting following message whenever i click on imageview
04-27 11:09:42.996: V/Provider/Settings(1018): from settings cache , name = sound_effects_enabled , value = 0
also i want to let you know that if i load any fragment in flMain, in that fragment all event is working fine but not on main layout :( also in llMainSlider noting was happening :(
Why don't you try declaring the event on the XML?
It is as simple as this
android:id="#+id/ivMainMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:onClick="myNewMethod" <!--add this extra line!--->
android:src="#drawable/menu" />
and simply on your Main activity add the myNewMethod as am extra function like this
public class MainActivity extends FragmentActivity{
private ImageView ivMainMenu;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void myNewMethod(View v) {
System.out.println("showSlider clicked");
}
Good Luck ;)
I have created an activity and now I am trying to add an eventListener to a button:
But when I switch to the AddEntryActivity I get an SuperNotCalledException().
Any help is really appreciated!
public class AddEntryActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_entry);
ImageButton test = (ImageButton) findViewById(R.id.mg_add_entry_button_save);
...
Here is my activity_add_entry.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity$PlaceholderFragment"
android:background="#drawable/radialback">
<LinearLayout
android:orientation="vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:id="#+id/mg_overview"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_above="#+id/mg_menu_bar">
<EditText
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:inputType="numberDecimal">
</EditText>
<EditText
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:inputType="date"/>
<Spinner
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/mg_add_entry_spinner_categories"
android:entries="#array/basic_categories_array"
android:prompt="#string/abc_activity_chooser_view_see_all"></Spinner>
<Button
android:id="#+id/mg_add_entry_button_save"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="#string/mg_save"/>
</LinearLayout>
<LinearLayout
android:id="#+id/mg_menu_bar"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<ImageButton
android:id="#+id/mg_menu_button_add_entry"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/abc_ic_go"/>
</LinearLayout>
</RelativeLayout>
Hard to say without seeing your logcat, but chances are that you're overriding some method in the previous activity class (such as onPause or onStop), and you're missing the call to super.-
#Override
public void onPause() {
super.onPause();
// Your stuff
}
I've created an Android sliding drawer but when it is dismissed it is completely hidden. The behavior that I'm looking for is to have the first row of the drawer visible at all times. If this is possible what is the best way to attempt this?
This works for me:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button 1" />
<SlidingDrawer
android:id="#+id/slidingDrawer1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/button1"
android:content="#+id/content"
android:handle="#+id/handle" >
<Button
android:id="#+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Handle" />
<ScrollView
android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/content1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbars="vertical" >
<Button
android:id="#+id/button1a"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 1" />
<Button
android:id="#+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 2" />
</LinearLayout>
</ScrollView>
</SlidingDrawer>
</RelativeLayout>
And in main activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
actionsSlider = (SlidingDrawer) findViewById(R.id.slidingDrawer1);
actionsSlider.setOnDrawerCloseListener(new OnDrawerCloseListener() {
public void onDrawerClosed() {
firstButton = (Button) findViewById(R.id.button1);
firstButton.setVisibility(View.VISIBLE);
}
});
actionsSlider.setOnDrawerScrollListener(new OnDrawerScrollListener() {
public void onScrollStarted() {
if (!actionsSlider.isOpened()) {
findViewById(R.id.button1).setVisibility(View.GONE);
firstButton = (Button) findViewById(R.id.button1a);
}
}
#Override
public void onScrollEnded() {
}
});
}
I need a little help.I'm using a ViewFlipper to change views in TabActivity but not really sure how to do it.Here is my code :
MainActivity.class
public class Collections extends Activity implements OnClickListener {
ViewFlipper vFlip;
Button genre, recommended, soon;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.collections_layout);
vFlip = (ViewFlipper) findViewById(R.id.tags_flipper);
genre = (Button) findViewById(R.id.genre_btn);
genre.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
vFlip.getCurrentView();
}
});
recommended = (Button) findViewById(R.id.recom_btn);
recommended.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
vFlip.getCurrentView();
}
});
soon = (Button) findViewById(R.id.soon_btn);
soon.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
vFlip.getCurrentView();
}
});
}
}
I have three different xml, which I want to load with clicking the buttons.Here is the collection_layout.xml
Collection_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
<LinearLayout
android:id="#+id/actionbar"
android:layout_width="fill_parent"
android:layout_height="65px"
android:background="#drawable/pink_bar"
android:tileMode="repeat"
android:orientation="vertical">
<ImageView
android:src="#drawable/stampii_logo"
android:id="#+id/stampii_logo_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="20px"/>
</LinearLayout>
<LinearLayout
android:id="#+id/first_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:background="#d229ce">
<Button
android:id="#+id/genre_btn"
android:text="By Genre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp" />
<Button
android:id="#+id/recom_btn"
android:text="Recommended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp" />
<Button
android:id="#+id/soon_btn"
android:text="Expect Soon!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/flip"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF" >
<ViewFlipper
android:id="#+id/tags_flipper"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<include android:id="#+id/genre" layout="#layout/by_genre" />
<include android:id="#+id/recom" layout="#layout/recommended" />
<include android:id="#+id/soon" layout="#layout/expect_soon" />
</ViewFlipper>
</LinearLayout>
</LinearLayout>
So how can i do that?Thanks a lot!
Use ViewFlipper.setDisplayedChild
In my app I have implemented the SlidingDrawer and it is not working. Am I wrong in any place.
Drawer = (SlidingDrawer) findViewById(R.id.drawer);
Drawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
#Override
public void onDrawerOpened() {
Toast.makeText(getApplicationContext(),"Drawer Opened", Toast.LENGTH_SHORT).show();
}
});
similarly the setOnDrawerCloseListener is also not working and my XML file is:
<SlidingDrawer android:id="#+id/drawer"
android:background="#null" android:layout_height="fill_parent"
android:handle="#+id/handle" android:content="#+id/chat_history_container"
android:layout_width="fill_parent">
<ImageView android:id="#+id/handle" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="#drawable/chat_icon" />
<RelativeLayout android:id="#+id/chat_history_container"
android:layout_width="fill_parent" android:layout_height="wrap_content">
//Some TextViews here
</RelativeLayout>
</SlidingDrawer>
Try this Code :
Xml Code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:gravity="bottom"
android:background="#drawable/androidpeople">
<SlidingDrawer android:layout_width="wrap_content"
android:id="#+id/SlidingDrawer"
android:handle="#+id/slideHandleButton" android:content="#+id/contentLayout"
android:padding="10dip" android:layout_height="250dip">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/slideHandleButton" android:background="#drawable/closearrow">
</Button>
<LinearLayout android:layout_width="wrap_content" android:id="#+id/contentLayout" android:orientation="vertical" android:gravity="center|top" android:padding="10dip" android:background="#C0C0C0" android:layout_height="wrap_content">
<Button android:id="#+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Content"></Button>
<Button android:id="#+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Content"></Button>
<Button android:id="#+id/Button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Content"></Button>
Java Code :
public class slidingDrawerExample extends Activity {
Button slideHandleButton;
SlidingDrawer slidingDrawer;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
slideHandleButton = (Button) findViewById(R.id.slideHandleButton);
slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer);
slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
#Override
public void onDrawerOpened() {
slideHandleButton.setBackgroundResource(R.drawable.openarrow);
}
});
slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
#Override
public void onDrawerClosed() {
slideHandleButton.setBackgroundResource(R.drawable.closearrow);
}
});
}
}
Check this Link for Reference Sliding Drawer...