How to use two sliding drawer in android - android

When i made two sliding Drawer Onw Drawer is functional but other is not
What i have done is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="#FCFCFC" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"
android:layout_marginBottom="5px">
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_gravity="left" >
<SlidingDrawer android:layout_gravity="left"
android:orientation="horizontal" android:layout_width="wrap_content" android:id="#+id/SlidingDrawer" android:handle="#+id/slideHandleButton" android:content="#+id/contentLayout" android:padding="10dip" android:layout_height="60dip">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/slideHandleButton" android:background="#drawable/projectmain"></Button>
<LinearLayout android:layout_width="wrap_content" android:id="#+id/contentLayout" android:orientation="horizontal" android:gravity="center" android:padding="10dip" android:background="#drawable/selector" android:layout_height="wrap_content">
<TextView android:background="#drawable/selector" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFF" android:textStyle="bold" android:textSize="16sp" android:text="Unlock" android:gravity="center" />
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="#FCFCFC"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"
android:layout_marginBottom="5px">
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_gravity="left" >
<SlidingDrawer android:layout_gravity="left"
android:orientation="horizontal" android:layout_width="wrap_content" android:id="#+id/SlidingDrawer1" android:handle="#+id/slideHandleButton1" android:content="#+id/contentLayout" android:padding="10dip" android:layout_height="60dip">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/slideHandleButton1" android:background="#drawable/propertymain"></Button>
<LinearLayout android:layout_width="wrap_content" android:id="#+id/contentLayout" android:orientation="horizontal" android:gravity="center" android:padding="10dip" android:background="#drawable/selector" android:layout_height="wrap_content">
<TextView android:background="#drawable/selector" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFF" android:textStyle="bold" android:textSize="16sp" android:text="Unlock" android:gravity="center" />
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
What i have done on Java in is
I have opened both the drawer
like
setContentView(R.layout.main);
slideHandleButton = (Button) findViewById(R.id.slideHandleButton);
slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer);
slideHandleButton1 = (Button) findViewById(R.id.slideHandleButton);
slidingDrawer1 = (SlidingDrawer) findViewById(R.id.SlidingDrawer);
slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
#Override
public void onDrawerOpened() {
Intent intent=new Intent(CurrentActivity.this,New Activity.class);
startActivity(intent);
}
});
slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
#Override
public void onDrawerClosed() {
}
});
slidingDrawer1.setOnDrawerOpenListener(new OnDrawerOpenListener() {
#Override
public void onDrawerOpened() {
Intent intent=new Intent(CurrentActivity.this,NewActivity.class);
startActivity(intent);
}
});
slidingDrawer1.setOnDrawerCloseListener(new OnDrawerCloseListener() {
#Override
public void onDrawerClosed() {
}
});
But Sliding Drawer 2nd is not working Please Help
Thanks in advance !!

Change this
slidingDrawer1 = (SlidingDrawer) findViewById(R.id.SlidingDrawer);
to
slidingDrawer1 = (SlidingDrawer) findViewById(R.id.SlidingDrawer1);
Looks like you have provided the same id to both the elements.

lOOK AT your java code you have used same id for both Sliding drawer

Related

couldnt save which view has focus?

my app contains "Settings" activity which contains 2 imagebuttons "back" and "about", whenever i press any of these buttons i get:
"couldnt save which view has focus because the focused view android.widget.LinearLayout#4055a9e0 has no id"
the xml code for my_settings:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ll2"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="15" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_margin="8dp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/settings" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|end"
android:orientation="horizontal" >
<ToggleButton
android:id="#+id/tb1"
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="#string/sett1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/border2"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/ll_set_back"
android:layout_margin="3dp"
android:gravity="center"
android:layout_weight="1"
android:orientation="vertical" >
**<ImageButton
android:id="#+id/st_ibt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/action_btn"
android:src="#drawable/back_ic" />**
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/back"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/ll_set_about"
android:layout_margin="3dp"
android:gravity="center"
android:layout_weight="1"
android:orientation="vertical" >
**<ImageButton
android:id="#+id/st_ibt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/action_btn"
android:src="#drawable/about_ic" />**
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/about"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
dont pay attention to the "scrollview" (i dont think the problem is there), just look at the end of the code for the 2 imagebuttons..
and this the java code for Settings:
public class Settings extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.my_settings);
//code...
ImageButton goBack=(ImageButton)findViewById(R.id.st_ibt1);
ImageButton about=(ImageButton)findViewById(R.id.st_ibt2);
goBack.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intent=new Intent(Settings.this, MainActivity.class);
startActivity(intent);
//finish();
}
});
about.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intent=new Intent(Settings.this, About.class);
startActivity(intent);
//finish();
}
});
}
so, how to fix this? i dont understand what this error means.. any suggestions
I think the problem is :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical" >
You enable focus to this LinearLayout, but you didn't provide any id for it.

Button overriding listview items and how to add textview just above listview

I have a listview between header and button, I want to add textview just above listview and button to align properly so that button do not override listview items. How can i do that? Not sure what is the issue with xml layout
layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#e7ebee"
android:gravity="center"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="452dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/mainheader"
android:layout_width="fill_parent"
android:layout_height="52dp"
android:background="#0a2436">
<RelativeLayout
android:id="#+id/subheader"
android:layout_width="wrap_content"
android:layout_height="52dp" >
<ImageView
android:id="#+id/back"
android:layout_width="40dip"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/my_highlight_drawable"
android:src="#drawable/back" />
<ImageView
android:id="#+id/inboxheader"
android:layout_width="2dip"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:layout_toRightOf="#+id/back"
android:background="#85929B"
android:paddingBottom="15dip"
android:paddingTop="15dip" />
</RelativeLayout>
<ImageView
android:id="#+id/windowtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:contentDescription="#null"
android:src="#drawable/logo" />
</RelativeLayout>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:divider="#android:color/darker_gray"
android:dividerHeight="1dip"
android:drawSelectorOnTop="false"
android:focusable="false"
android:paddingTop="0dip" />
<TextView
android:id="#+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="No Data Available"
android:visibility="invisible" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:gravity="bottom">
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#092435"
android:gravity="center_horizontal" >
<Button
android:id="#+id/btnManualLookup"
android:layout_width="0dp"
android:layout_weight="1"
android:background="#4982AE"
android:gravity="center"
android:padding="15dip"
android:text="Submit"
android:textColor="#ffffff" />
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
Have you considered adding a headerview to listview. You could actually use a layout as header for listview. This way, you views on header will never overflow on to listview.
final ListView lstVRHDetails = (ListView) getActivity().findViewById(R.id.listview);
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View headerView = inflater.inflate(<header layout>, new LinearLayout(getActivity()), false);
headerView.findViewById(R.id.rlFromDate).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
}
});
headerView.findViewById(R.id.rlToDate).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
}
});
headerView.findViewById(R.id.imgUpdate).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
}
});
headerView.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, ListView.LayoutParams.WRAP_CONTENT));
lstVRHDetails.addHeaderView(headerView);

Android Sliding Drawer with first row always visible

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() {
}
});
}

Android Application force closes. (NullPointerException / ToggleButton)

My Code:
public class My_Application extends Activity {
public ToggleButton privBtn = (ToggleButton) findViewById(R.id.privacyShow);
public LinearLayout privLay = (LinearLayout) findViewById(R.id.privacyLayout);
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
privBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(privBtn.isChecked()) {
privLay.setVisibility(LinearLayout.VISIBLE);
}
else {
privLay.setVisibility(LinearLayout.INVISIBLE);
}
}
});
}
}
When I launch the application it force closes. I debugged the application with the built-in Dev Tools application in the emulator, and see the following:
[2011-06-23 20:27:06 - ddms]null
java.lang.NullPointerException
at com.android.ddmlib.Client.sendAndConsume(Client.java:572)
at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142)
at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65)
at com.android.ddmlib.Client.getJdwpPacket(Client.java:671)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)
As well as a "Source not found." error at:
ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2417
main.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"
>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="My Application" android:gravity="center_horizontal"
android:textSize="25dp" android:background="#222" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text=" Server IP: " android:textSize="20dp" android:textColor="#0F0"
android:layout_weight="0.7" />
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content"
android:hint="eg: 0.0.0.0" android:layout_weight="0.5" android:textSize="20dp"
android:id="#+id/loginIP" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Server Port: " android:textSize="20dp" android:textColor="#0F0"
android:layout_weight="0.7" />
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content"
android:hint="eg: 1234" android:layout_weight="0.5" android:textSize="20dp"
android:id="#+id/loginPort" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:id="#+id/privacyLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Privacy Options" android:textSize="20dp" android:textColor="#0F0"
android:layout_weight="0.4" />
<ToggleButton android:layout_width="fill_parent" android:layout_height="wrap_content"
android:checked="false" android:layout_weight="0.6" android:textOff="Show Options"
android:textOn="Hide Options" android:id="#+id/privacyShow" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:visibility="invisible"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content"
>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Username: " android:textColor="#0F0" android:textSize="15dp"
android:layout_weight="0.5" />
<EditText android:layout_width="fill_parent" android:layout_height="30dp"
android:id="#+id/privacyUsername" android:textSize="15dp" android:layout_weight="0.2" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content"
>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Password: " android:textColor="#0F0" android:textSize="15dp"
android:layout_weight="0.5" />
<EditText android:layout_width="fill_parent" android:layout_height="30dp"
android:id="#+id/privacyPassword" android:textSize="15dp" android:layout_weight="0.2" />
</LinearLayout>
</LinearLayout>
You can't set the privBtn and privLay before the setContentView() is called. Move those two statements into your onCreate().
public class My_Application extends Activity {
public ToggleButton privBtn;
public LinearLayout privLay;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
privBtn = (ToggleButton) findViewById(R.id.privacyShow);
privLay = (LinearLayout) findViewById(R.id.privacyLayout);
privBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(privBtn.isChecked()) {
privLay.setVisibility(LinearLayout.VISIBLE);
}
else {
privLay.setVisibility(LinearLayout.INVISIBLE);
}
}
});
}
}

SlidingDrawer not working

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...

Categories

Resources