2014-04-21 101 views
0

我必须在Android中创建一个列表菜单项,其中包含三个菜单项在列表视图中我想显示一些内容点击每个菜单。这里是其中的一个屏幕到目前为止,我已经做了.. enter image description here如何在Android应用程序中单击显示菜单项

这是我创建。我想,我会点击菜单1和菜单1将在page..i显示我张贴我的代码菜单..

public class MainActivity extends ListActivity { 

String[] menus={"Menu1","Menu2","Menu3"}; 

@Override 
protected void onListItemClick(ListView l,View v,int position,long id){ 
    super.onListItemClick(l,v,position,id); 

    String name=menus[position]; 

    try{ 
     Class main=Class.forName("com.betacoading.createlistmenu.app"+name); 
     Intent intent=new Intent(MainActivity.this,main); 
     startActivity(intent); 

    }catch(ClassNotFoundException e){ 
     e.printStackTrace(); 
    } 

} 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
// setContentView(R.layout.activity_main); 
    setListAdapter(new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_expandable_list_item_1,menus)); 
} 


@Override 
public boolean onCreateOptionsMenu(Menu menu) { 

    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
    } 






@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
    } 

    } 




public class Menu_1 extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState){ 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.menu_1); 

    Button back=(Button)findViewById(R.id.button); 

    back.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Intent in=new Intent(getApplicationContext(),MainActivity.class); 
      startActivity(in); 
     } 
    }); 
} 

} 


public class Menu_2 extends Activity { 


@Override 
protected void onCreate(Bundle savedInstanceState){ 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.menu_2); 

    Button back=(Button)findViewById(R.id.button); 

    back.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Intent in=new Intent(getApplicationContext(),MainActivity.class); 
      startActivity(in); 
     } 
    }); 
    } 

    } 




public class Menu_3 extends Activity { 


@Override 
protected void onCreate(Bundle savedInstanceState){ 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.menu_3); 

    Button back=(Button)findViewById(R.id.button); 

    back.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Intent in=new Intent(getApplicationContext(),MainActivity.class); 
      startActivity(in); 
     } 
    }); 
} 

} 


AndroidManifest.xml 

    <?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.betacoading.createlistmenu.app" > 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.betacoading.createlistmenu.app.MainActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name=".Menu_1" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <category android:name="android.intent.category.DEFAULT" /> 

     </intent-filter> 
    </activity> 
    <activity 
     android:name=".Menu_2" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <category android:name="android.intent.category.DEFAULT" /> 

     </intent-filter> 
    </activity> 
    <activity 
     android:name=".Menu_3" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <category android:name="android.intent.category.DEFAULT" /> 

     </intent-filter> 
    </activity> 
    </application> 

    </manifest> 



Menu_1.xml 


<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 


<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Menu 1" 
    android:textSize="24dp" 
    android:layout_gravity="center_horizontal" 

    /> 

<Button 
    android:id="@+id/button" 
    android:layout_width="200dp" 
    android:layout_height="400dp" 
    android:text="Back" 
    android:textSize="16dp" 
    /> 




</LinearLayout> 


Menu2.xml 



    <?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 


<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Menu 2" 
    android:textSize="24dp" 
    android:layout_gravity="center_horizontal" 

    /> 

<Button 
    android:id="@+id/button" 
    android:layout_width="200dp" 
    android:layout_height="400dp" 
    android:text="Back" 
    android:textSize="16dp" 
    /> 




</LinearLayout> 


menu3.xml 


    <?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 


<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Menu 3" 
    android:textSize="24dp" 
    android:layout_gravity="center_horizontal" 

    /> 

<Button 
    android:id="@+id/button" 
    android:layout_width="200dp" 
    android:layout_height="400dp" 
    android:text="Back" 
    android:textSize="16dp" 
    /> 

这是我试过的代码所以far..please帮助我,使之动态

回答

1

尝试此链接

http://www.androidviews.net/2013/04/sliding-layer/

这将有助于你做出滑动从下,左,右菜单,上面有很多的动画。

你可以把任何东西放在它里面,并轻松地在你的java类中工作。

希望它会有所帮助。

+0

确定我正在尝试一个问题,可以用eclipse编辑吗?我是新来的android .... – lucifer

+0

是的,它是一个开源的库..你可以很容易地在你的项目中实现它通过参考库。 – Shivansh

相关问题