gpt4 book ai didi

java - 如何使用 GridView 打开 Activity 。安卓

转载 作者:行者123 更新时间:2023-11-29 04:29:23 28 4
gpt4 key购买 nike

我在打开新 Activity 时遇到问题,当单击元素 0 向我发送 Activity 时,但这不会显示内容,也不会向我发送一些错误,并在 androidManifest.xml 中添加了新 Activity 。我会留下我的代码:

AndroidManifest.xml

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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".leon">
</activity>


</application>

</manifest>

MainActivity.java

package com.example.ivann.diuxgridmain;

import android.content.Intent;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
GridView androidGridView;

String[] gridViewString = {
"Leon1", "Ave1", "Perro1", "Cara1", "Corazòn1", "Enojado1",
"Leon2", "Ave2", "Perro2", "Cara2", "Corazòn2", "Enojado2",
"Leon3", "Ave3", "Perro3", "Cara3", "Corazòn3", "Enojado3",

} ;
int[] gridViewImageId = {
R.drawable.leon, R.drawable.bird, R.drawable.cachorro, R.drawable.fb, R.drawable.heart, R.drawable.angry,
R.drawable.leon, R.drawable.bird, R.drawable.cachorro, R.drawable.fb, R.drawable.heart, R.drawable.angry,
R.drawable.leon, R.drawable.bird, R.drawable.cachorro, R.drawable.fb, R.drawable.heart, R.drawable.angry,


};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

CustomGridViewActivity adapterViewAndroid = new CustomGridViewActivity(MainActivity.this, gridViewString, gridViewImageId);
androidGridView=(GridView)findViewById(R.id.grid_view_image_text);
androidGridView.setAdapter(adapterViewAndroid);
androidGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
int i, long id) {
Intent intent=null;
switch (i){
case 0:
// I think here is the error *******
intent = new Intent(MainActivity.this, leon.class);
startActivity(intent);
break;
}
Toast.makeText(MainActivity.this, "GridView Item: " + gridViewString[+i ], Toast.LENGTH_LONG).show();
}
});

}

}

leon.java

package com.example.ivann.diuxgridmain;

import android.app.Activity;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

/**
* Created by ivann on 09/06/2017.
*/

public class leon extends Activity {
@Override
public void onCreate(Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.leonactividad);

}
}

最佳答案

只是删除

这个

 @Override
public void onCreate(Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.leonactividad);

}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.leonactividad);

}

关于java - 如何使用 GridView 打开 Activity 。安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44453914/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com