繁体   English   中英

GridView 显示为黑色/白色背景但没有任何信息

[英]GridView shows up as black/white background but without any information

我有这种问题,当我尝试打开它时,这是 GridView

它只是显示为黑色。 在空的新项目中对其进行了测试,在新项目中它运行良好,没有任何问题。 在我的项目中,我正在与 google map sdk、用户 firebase 和相册 gridview 合作。 我现在想向您展示我的清单、实现和代码。

我的清单

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.buchqiversion2" >
    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the "MyLocation" functionality.
    -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <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/Theme.BuchqiVersion2" >

        <activity
            android:name=".FullView"
            android:theme="@style/fullViewTheme">
        </activity>

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

        <activity
            android:name=".GridView"
            android:exported="true">
        </activity>

        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps" />
        <activity
            android:name=".PhoneLoginActivity" />

        <activity
            android:name=".LoginActivity"
            android:exported="true" />

        <activity
            android:name=".MainActivity"
            android:exported="true" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

我的 GridView 代码

    android.widget.GridView gridView;
    ActivityGridviewBinding binding;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        
        binding = ActivityGridviewBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        
        Toast.makeText(this,"grid started",Toast.LENGTH_SHORT).show();
        String[] items = {"Mishka's Room"};
        
        int[] images = {R.drawable.login_background};
        ImageAdapter imageAdapter = new ImageAdapter(this,items,images);
        
        binding.myGridView.setAdapter(imageAdapter);
        Toast.makeText(this, "Map is ready", Toast.LENGTH_SHORT).show();
    }

图片适配器

    private Context mContext;
    String[] items;
    int[] image;

    LayoutInflater layoutInflater;

    public ImageAdapter(Context context, String[] items, int[] image) {
        this.mContext = context;
        this.items = items;
        this.image = image;
    }

    @Override
    public int getCount() {
        return items.length;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (layoutInflater == null){
            layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }

        if (convertView == null){
            convertView = layoutInflater.inflate(R.layout.grid_item,null);
        }

        ImageView imageView = convertView.findViewById(R.id.grid_image);
        TextView textView = convertView.findViewById(R.id.item_name);

        imageView.setImageResource(image[position]);
        textView.setText(items[position]);

        return convertView;
    }

实现

    plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'




    defaultConfig {
        applicationId "com.example.buchqiversion2"
        minSdkVersion 19
        targetSdkVersion 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    buildFeatures {
        viewBinding true
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }



    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.google.android.gms:play-services-location:19.0.1'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    implementation 'com.google.firebase:firebase-auth:21.0.1'
    implementation 'com.google.android.gms:play-services-maps:18.0.2'
    implementation 'org.jetbrains:annotations:15.0'
    //testImplementation 'junit:junit:'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    //Glide//
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'

    //Material Design//
    implementation'com.google.android.material:material:1.5.0'

    //Animato Dependency//
    implementation 'com.github.mohammadatif:Animatoo:master'

    //Country Code//
    implementation 'com.hbb20:ccp:1.7.1'

    //Retrofit Dependency//
    implementation'com.squareup.retrofit2:retrofit:2.9.0'
    implementation'com.squareup.retrofit2:converter-gson:2.9.0'

    //Pin View//
    implementation 'com.chaos.view:pinview:1.4.4'
    //Pin View// 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM