所以我有2個活動,並在第一個我有一個菜單項,一旦點擊應打開第二個活動。不斷變化的部分作品,但它不會改變什麼是應該,在我與這個激活第二個活動:當點擊一個菜單項按鈕時,打開一個新的活動不起作用
Intent intent = new Intent(this, EditView.class);
startActivity(intent);
break;
中的第一個活動onOptionsItemSelected,我從菜單中點擊一個按鈕,在本次活動我有一個不同的佈局,我做這個setContentView(R.layout.second);改變佈局我有一個功能的XML文件,因爲我在另一個項目中試了一下,在清單文件中我有這樣的:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ro.merca.ionel"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".FileList"
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=".EditView"
android:label="@string/app_name" />
</application>
</manifest>
的問題是,當我從菜單中單擊該選項加載一個簡單的佈局沒有所有我把second.xml的事情......我不知道問題是...
public class EditView extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
Intent intent = getIntent();
TextView tv = new TextView(this);
final TextView name = (TextView) findViewById(R.id.name);
final TextView text = (TextView) findViewById(R.id.text);
setContentView(tv);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(1,1,1,"Salveaza Nota").setIcon(android.R.drawable.btn_default);
menu.add(1,2,2,"Anuleaza Modificari").setIcon(android.R.drawable.btn_default);
menu.add(1,3,3,"Sterge Nota").setIcon(android.R.drawable.btn_default);
menu.add(1,4,4,"Share").setIcon(android.R.drawable.btn_default);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case 1 :
Intent intent = new Intent(this, EditView.class);
this.startActivity(intent);
break;
case 2 :
break;
case 3 :
break;
case 4 :
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Nume" />
<EditText
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text" />
<EditText
android:id = "@+id/text"
android:inputType="text|textMultiLine"
android:minLines="5"
android:gravity="top"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
您需要發佈您的代碼的第二個活動(EditView中)。 – wyoskibum
並且還放置了第二個佈局的xml。 –
請發佈第二個活動和佈局的代碼和xml。 –