我只使用android studio一天。我必须为我的学校项目创建一个应用程序,我做到了,我在android studio中编程并且它没有错误。请帮忙, 这是名为frontpagee的主要活动
package com.example.lenovo.shop_easy;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class frontpagee extends Activity
{
public void sendMessage(View view){
Intent intent = new Intent(frontpagee.this, catalog.class);
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_frontpagee, 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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
XML就像这样
我想从此活动转移到名为Catalog的第二个ACTIVITY java是
package com.example.lenovo.shop_easy;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class catalog extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_catalog);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_catalog, 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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void sendMessage(View view) {
Intent intent = new Intent(catalog.this, product1.class);
startActivity(intent);
}
public void sendMessage1(View view) {
Intent intent = new Intent(catalog.this, PRODUCT2.class);
startActivity(intent);
}
public void sendMessage2(View view) {
Intent intent = new Intent(catalog.this, PRODUCT3.class);
startActivity(intent);
}
public void sendMessage3(View view) {
Intent intent = new Intent(catalog.this, product4.class);
startActivity(intent);
}
public void sendMessage4(View view) {
Intent intent = new Intent(catalog.this, product5.class);
startActivity(intent);
}
public void sendMessage5(View view) {
Intent intent = new Intent(catalog.this, product6.class);
startActivity(intent);
}
public void sendMessage6(View view) {
Intent intent = new Intent(catalog.this, product7.class);
startActivity(intent);
}
public void sendMessage7(View view) {
Intent intent = new Intent(catalog.this, product8.class);
startActivity(intent);
}
public void sendMessage8(View view) {
Intent intent = new Intent(catalog.this, product9.class);
startActivity(intent);
}
public void sendMessage9(View view) {
Intent intent = new Intent(catalog.this, product10.class);
startActivity(intent);
}
}
<FrameLayout 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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".frontpagee"
android:background="@drawable/back">
<ImageView
android:layout_width="472dp"
android:layout_height="500dp"
android:id="@+id/imageView11"
android:src="@mipmap/cover"
android:layout_gravity="center_horizontal|top"
android:contentDescription="@string/content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text12"
android:id="@+id/button11"
android:layout_gravity="center_horizontal|bottom"
android:textSize="@dimen/size2"
android:clickable="true"
android:onClick="sendMessage"/>
</FrameLayout>
代码是正确的说安卓工作室,但当我在我的手机上运行adb它安装应用程序,一切顺利,但当我打开应用程序时它只显示应用程序图标和顶部的名称,没有别的什么去做。请帮忙
这里的主要xml文件也是
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lenovo.shop_easy" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".frontpagee"
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=".catalog"
android:label="@string/title_activity_catalog" >
</activity>
<activity
android:name=".product1"
android:label="@string/title_activity_product1" >
</activity>
<activity
android:name=".PRODUCT2"
android:label="@string/title_activity_product2" >
</activity>
<activity
android:name=".PRODUCT3"
android:label="@string/title_activity_product3" >
</activity>
<activity
android:name=".product4"
android:label="@string/title_activity_product4" >
</activity>
<activity
android:name=".product5"
android:label="@string/title_activity_product5" >
</activity>
<activity
android:name=".product6"
android:label="@string/title_activity_product6" >
</activity>
<activity
android:name=".product7"
android:label="@string/title_activity_product7" >
</activity>
<activity
android:name=".product8"
android:label="@string/title_activity_product8" >
</activity>
<activity
android:name=".product9"
android:label="@string/title_activity_product9" >
</activity>
<activity
android:name=".product10"
android:label="@string/title_activity_product10" >
</activity>
</application>
</manifest>
该怎么做
答案 0 :(得分:2)
您尚未覆盖onCreate(Bundle savedInstance)
中的class frontpagee
方法,并且未在其中调用setContentView(R.layout...)
。