2015-04-12 87 views
2

原谅我的英语,我是新的Android和创建应用程序。每件事情都正常工作,但我有一个很小的问题是,在导航抽屉里,当我点击项目时,只是导航抽屉被关闭多数民众赞成它没有错误没有任何东西错误的logcat真的我不知道,但我想布局从mybe。 我的布局:listview item not working in导航抽屉

<?xml version="1.0" encoding="utf-8"?> 
     <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"> 

     <LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/container" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent" 
      tools:context=".MyPayamak" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:divider="@null" 
     android:background="#ffffff" 
     android:dividerHeight="10sp" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp"> 
    </ListView> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/tt"/> 

    <ProgressBar 
     android:layout_width="45dp" 
     android:layout_height="45dp" 
     android:layout_gravity="center" 
     android:id="@+id/progressBar"/> 

     </LinearLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="@drawable/bar" 
     android:orientation="vertical"> 

     <!-- Side navigation drawer UI --> 


     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="کاربر میهمان" 
      android:textColor="#3D3D3D" 
      android:background="#ffffff" 
      android:layout_gravity="center" 
      android:gravity="center" 
      android:padding="15dp" 
      android:id="@+id/ShowFakenameOfUser"/> 

     <ImageView 
      android:layout_marginTop="10dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:src="@drawable/usericon"/> 

     <ListView 
      android:id="@+id/navList" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:divider="@null" 
      android:dividerHeight="10dp" 
      android:layout_marginTop="20dp" 
      android:paddingLeft="20dp" 
      android:paddingRight="20dp"/> 

    </LinearLayout> 
</android.support.v4.widget.DrawerLayout> 

还有一件事我的抽屉式导航栏的代码是在所有的活动一样,做工精细,但2的活性有这个问题,使用此布局。

在我的OnCreate

有这样的代码:

mDrawerList = (ListView)findViewById(R.id.navList); 
    mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout); 
    mActivityTitle = getTitle().toString(); 



    mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 

      if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("ورود")) { 
       Intent it = new Intent(List_Payamak_ha.this, loginUser.class); 
       startActivity(it); 
      }else if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("ثبت نام")){ 
       Intent it = new Intent(List_Payamak_ha.this, RegisterUser.class); 
       startActivity(it); 
      }else if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("کاربران فعال")) { 
       Intent it = new Intent(List_Payamak_ha.this, ActiveUsers.class); 
       startActivity(it); 
      }else if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("کاربران برتر")) { 
       Intent it = new Intent(List_Payamak_ha.this, TopUsers.class); 
       startActivity(it); 
      }else if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("درباره نرم افزار")) { 
       Intent it = new Intent(List_Payamak_ha.this, AboutPage.class); 
       startActivity(it); 
      }else if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("خروج")) { 
       int pid = android.os.Process.myPid(); 
       android.os.Process.killProcess(pid); 
       finish(); 
       System.exit(0); 
      } 

     } 
    }); 


    addDrawerItems(); 
    setupDrawer(); 

整个代码:

private void addDrawerItems() { 
     String[] osArray = getResources().getStringArray(R.array.SlideMenu); 
     mAdapterCopy = new MenuSideAdapterItem(this, 
       android.R.layout.simple_list_item_1, 
       R.id.textViewMenuSide, 
       osArray); 
     mDrawerList.setAdapter(mAdapterCopy); 

    } 

    private void setupDrawer() { 
; 
     mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, 
       R.string.drawer_open, R.string.drawer_close) { 

      /** Called when a drawer has settled in a completely open state. */ 
      public void onDrawerOpened(View view) { 
       super.onDrawerOpened(view); 
       getSupportActionBar().setTitle("منو"); 
       invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() 
      } 


      /** Called when a drawer has settled in a completely closed state. */ 
      public void onDrawerClosed(View view) { 
       super.onDrawerClosed(view); 
       getSupportActionBar().setTitle(mActivityTitle); 
       invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() 
      } 

     }; 

     mDrawerToggle.setDrawerIndicatorEnabled(true); 
     mDrawerLayout.setDrawerListener(mDrawerToggle); 
    } 

    @Override 
    protected void onPostCreate(Bundle savedInstanceState) { 
     super.onPostCreate(savedInstanceState); 
     mDrawerToggle.syncState(); 
    } 
    @Override 
    public void onConfigurationChanged(Configuration newConfig) { 
     super.onConfigurationChanged(newConfig); 
     mDrawerToggle.onConfigurationChanged(newConfig); 
    } 

    private class MenuSideAdapterItem extends ArrayAdapter<String> { 

     public MenuSideAdapterItem(Context context, int resource, int textViewResourceId, String[] objects) { 
      super(context, resource, textViewResourceId, objects); 
     } 

     @Override 
     public View getView(int position, View convertView, ViewGroup parent) { 
      LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      View Row = inflater.inflate(R.layout.menu_item,parent,false); 
      String[] items = getResources().getStringArray(R.array.SlideMenu); 

      ImageView IconView = (ImageView) Row.findViewById(R.id.imageViewMenuSide); 
      TextView textMenuSide = (TextView) Row.findViewById(R.id.textViewMenuSide); 
      textMenuSide.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/Far_TitrDF.ttf")); 

      textMenuSide.setText(items[position]); 

      if (items[position].equalsIgnoreCase("ورود")){ 
       IconView.setImageResource(R.drawable.loginicon); 
      }else if (items[position].equalsIgnoreCase("ثبت نام")){ 
       IconView.setImageResource(R.drawable.registericoon); 
      }else if (items[position].equalsIgnoreCase("کاربران فعال")){ 
       IconView.setImageResource(R.drawable.activeuser); 
      }else if (items[position].equalsIgnoreCase("کاربران برتر")){ 
       IconView.setImageResource(R.drawable.topuser); 
      }else if (items[position].equalsIgnoreCase("درباره نرم افزار")){ 
       IconView.setImageResource(R.drawable.about); 
      }else if (items[position].equalsIgnoreCase("خروج")){ 
       IconView.setImageResource(R.drawable.exit); 
      } 
      return Row; 
     } 
    } 
+0

您的问题究竟是什么? – natario

+0

@m iav - listview项目不可点击当我点击listview刚刚关闭导航抽屉! – Hosseini

+0

您的意思是您的点击除了关闭抽屉之外没有任何效果?你如何管理ListView上的点击事件?显示你的活动代码。 – natario

回答

1

问题是从另一个片段,在屏幕的底部用来显示图像,片段是在最上面的抽屉时,我在抽屉单击其实是我在片段点击,所以我从来没有触及上的按钮,因为我与RelativeLayout取代fragment,解决我的问题。

0

我觉得控制是不是在你的,如果条件等做如下的

1打印消息会每个if语句使用

Log.i("tag","any_message"); 

System.out.println("any_message"); 

2还打印添加else语句适当消息

,并通过这种方式,你会知道的控制是否会内部if语句或不检查logcat的。

+0

不能正常工作.... – Hosseini

+0

做了befor先生,但仍然不工作其跳过setOnItemClickListener,我试着android:focusable =“false” android:focusableInTouchMode =“false”each parent layout – Hosseini