我已經Implented抽屜採用了滑蓋聽者 但是換手指請告訴我,我做錯了什麼,當它不工作:這裏 是我的frag類Android的滑動抽屜不工作
public class frag extends android.support.v4.app.Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.lists , container);
return view;
}
public void setUp(int Fid ,DrawerLayout drawerLayout)
{
drawerLayout = (DrawerLayout)getActivity().findViewById(R.id.drawer);
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
final ActionBar ab = getActivity().getActionBar();
ActionBarDrawerToggle abdl = new ActionBarDrawerToggle(
getActivity(),
drawerLayout,
R.string.action_settings ,
R.string.hello_world) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
ab.setTitle("closed");
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
ab.setTitle("opened");
}
};
drawerLayout.setDrawerListener(abdl);
}
public void close()
{
DrawerLayout drawerLayout = (DrawerLayout)getActivity().findViewById(R.id.drawer);
drawerLayout.closeDrawers();
}
}
這裏是佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="240dp"
android:id="@+id/dll"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="right"
android:id="@+id/drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
>
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/sidebarlist"
android:text="thadssasdisk"
android:textAlignment="center">
</ListView>
</android.support.v4.widget.DrawerLayout>
滑塊不工作,我想創建一個側面抽屜式導航類 ŧ他活動:
package com.example.shubham.navigation;
import android.content.Context;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Layout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import java.util.List;
public class MainActivity extends AppCompatActivity {
DrawerLayout dl;
frag fg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fg = (frag)getSupportFragmentManager().findFragmentById(R.id.sidebar);
fg.setUp(R.id.drawer, (DrawerLayout) findViewById(R.id.drawer));
ListView lv = (ListView)findViewById(R.id.sidebarlist);
drawer aa = new drawer(this);
lv.setAdapter(aa);
aa.add("text");
aa.add("fun");
aa.add("learn");
aa.add("To do");
aa.add("Pending");
aa.add("Current");
aa.add("future");
aa.add("Learn");
aa.add("tasks");
aa.notifyDataSetChanged();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onPostCreate(Bundle savedInstanceState)
{
super.onPostCreate(savedInstanceState);
fg.onViewStateRestored(savedInstanceState);
fg.abdl.syncState();
}
}
的alyout文件wher片段稱爲:
<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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tview"
android:text="hello world you know who"
android:visibility="invisible"
/>
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/sidebar"
class="com.example.shubham.navigation.frag"
></fragment>
</RelativeLayout>
它正在做什麼? –
在'onCreateView'中調用'setUp' –
其他任何人仍然不工作 – user49557