mahdi
mahdi

Reputation: 16407

android:button tap event on base activity

i create a BaseActivity for same layout for all activitys and sliding menu in my app, i have a button in base activity layout and my problem is when i tap on button no things happens and this message shown on log:

D/VelocityTracker﹕ Couldn't open '/dev/touch' (Permission denied)
D/VelocityTracker﹕ tpd read x fail: Bad file number
D/VelocityTracker﹕ tpd read y fail: Bad file number
D/VelocityTracker﹕ Couldn't open '/dev/touch' (Permission denied)
D/VelocityTracker﹕ tpd read x fail: Bad file number
D/VelocityTracker﹕ tpd read y fail: Bad file number
I/View﹕ Touch down dispatch to android.widget.Button{424d3700 VFED..C. ........ 27,27-70,70 #7f070052 app:id/button_menu}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=27.332088, y[0]=3.7002335, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=182860652, downTime=182860652, deviceId=2, source=0x1002 }
I/View﹕ Touch up dispatch to android.widget.Button{424d3700 VFED..C. ...p.... 27,27-70,70 #7f070052 app:id/button_menu}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=24.136082, y[0]=3.7002335, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=182860725, downTime=182860652, deviceId=2, source=0x1002 }

this is my base activity layout :

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- Put what you want as your normal screen in here, you can also choose for a linear layout or any other layout, whatever you prefer -->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFFFFF"
        android:id="@+id/sub_layout"
       >
        <Button
            android:id="@+id/button_menu"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/menu"
            android:text="Ok" />

    </RelativeLayout>
</FrameLayout>
<!-- The navigation drawer -->
<RelativeLayout
    android:id="@+id/left_drawer"
    android:layout_width="250dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp">
</RelativeLayout>

and this is my base activity code :

public class BaseActivity extends Activity {

protected FrameLayout frameLayout;

protected RelativeLayout mDrawerList;


protected static int position;

private static boolean isLaunch = true;

protected DrawerLayout mDrawerLayout;

private ActionBarDrawerToggle actionBarDrawerToggle;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_base);

    frameLayout = (FrameLayout) findViewById(R.id.content_frame);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (RelativeLayout) findViewById(R.id.left_drawer);



    Button btn_menu = (Button) findViewById(R.id.button_menu);
    btn_menu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mDrawerLayout.openDrawer(mDrawerList);
            Log.d("Menu is open","???");
        }
    });


}

i don`t understand what is the problem. can any body help me ? thanks

Upvotes: 1

Views: 2279

Answers (2)

Deepak Ganachari
Deepak Ganachari

Reputation: 416

There is some bug for listview On click in Relative layout, you have to add an attribute called android:descendantFocusability="blocksDescendants" to solve..

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">
..........
</RelativeLayout>

Hope this helps..

Upvotes: 1

Lucas
Lucas

Reputation: 151

There's a problem in your xml.. You are closing an RelativeLayout that doesn't exists..

<FrameLayout>
--- <RelativeLayout>
-------- <Button></Button>
--- </RelativeLayout>
--- </RelativeLayout> *THIS*
</FrameLayout>

Upvotes: 1

Related Questions