主要活动不会在Bluestack中加载

发布于 2025-01-17 21:00:19 字数 5052 浏览 0 评论 0原文

有关代码的背景:

我建造建筑物列表,并有照片。

我添加到搜索栏的列表。当一个人搜索并单击特定建筑物时,照片需要在屏幕底部弹出。

我试图在BlueStacks上运行该应用程序,但主要活动并没有弹出!

我试图更改主要活动中代码的位置,但没有任何作用... Android Studio中的设计部分工作起作用,当我在Bluestack上运行它时,它看起来不错。

代码:

主要活动

package com.example.Building;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SearchView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    ListView search_buildings;
    ArrayAdapter<String> adapter;


    void OnItemClickListener(AdapterView<?> adapter, View v, int position){

        if (position == 1)
        {
            ImageView imgView1 = (ImageView)findViewById(R.id.b1);//imgView1.setVisibility(View.VISIBLE);
        }
        if (position == 2)
        {
            ImageView imgView1 = (ImageView)findViewById(R.id.b2);//imgView1.setVisibility(View.VISIBLE);
        }
        if (position == 3)
        {
            ImageView imgView1 = (ImageView)findViewById(R.id.b3);//imgView1.setVisibility(View.VISIBLE);
        }
        
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        search_buildings = (ListView) findViewById(R.id.search_buildings);
        ArrayList<String> arraybuildings = new ArrayList<>();
        arraybuildings.addAll(Arrays.asList(getResources().getStringArray(R.array.my_buildings)));
        adapter = new ArrayAdapter<String>(
                MainActivity.this,
                android.R.layout.simple_list_item_1,
                (List<String>) arraybuildings
        );
        search_buildings.setAdapter(adapter);
        // add on click for each Item by names and set the right pic
        // add pics that will go hand by hand with the Items name
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.search_menu, menu);
        MenuItem item = menu.findItem(R.id.search_buildings);
        SearchView searchView = (SearchView)item.getActionView();

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String s) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String s) {
                adapter.getFilter().filter(s);
                return false;
            }
        });
return super.onCreateOptionsMenu(menu);
    }
}

主XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="horizontal">

   <ListView
       android:id="@+id/search_buildings"
       android:layout_width="match_parent"
       android:layout_height="422dp"
       android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" />

   <ImageView
       android:id="@+id/b1"
       android:layout_width="294dp"
       android:layout_height="wrap_content"
       android:layout_gravity="top"
       android:layout_marginLeft="-350dp"
       android:layout_marginTop="450dp"
       android:visibility="invisible"
       app:srcCompat="@mipmap/a1" />

   <ImageView
       android:id="@+id/b2"
       android:layout_width="294dp"
       android:layout_height="wrap_content"
       android:layout_gravity="top"
       android:layout_marginLeft="-294dp"
       android:layout_marginTop="450dp"
       android:visibility="invisible"
       app:srcCompat="@mipmap/a2" />

   <ImageView
       android:id="@+id/b3"
       android:layout_width="294dp"
       android:layout_height="wrap_content"
       android:layout_gravity="top"
       android:layout_marginLeft="-294dp"
       android:layout_marginTop="450dp"
       android:visibility="invisible"
       app:srcCompat="@mipmap/a3" />

</LinearLayout>

字符串XML:

<resources>
    <string name="app_name">Building</string>

    <string-array name="my_buildings">
        <item>number1</item>
        <item>number2</item>
        <item>number3</item>
    </string-array>


</resources>

希望您能帮助我!

谢谢你!!

Background about the code:

I build a list of buildings and I have photos.

The list I added to the search bar. and when a person searches and clicks on a specific building the photo needs to pop on the bottom of the screen.

I tried to run the app on BlueStacks but the main activity isn't poping on!

I tried to change the positions of the code in the Main activity but nothing works...
The design part in the Android Studio works and seems good when I run it on BlueStack it doesn't loud.

The Code:

Main Activity

package com.example.Building;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SearchView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    ListView search_buildings;
    ArrayAdapter<String> adapter;


    void OnItemClickListener(AdapterView<?> adapter, View v, int position){

        if (position == 1)
        {
            ImageView imgView1 = (ImageView)findViewById(R.id.b1);//imgView1.setVisibility(View.VISIBLE);
        }
        if (position == 2)
        {
            ImageView imgView1 = (ImageView)findViewById(R.id.b2);//imgView1.setVisibility(View.VISIBLE);
        }
        if (position == 3)
        {
            ImageView imgView1 = (ImageView)findViewById(R.id.b3);//imgView1.setVisibility(View.VISIBLE);
        }
        
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        search_buildings = (ListView) findViewById(R.id.search_buildings);
        ArrayList<String> arraybuildings = new ArrayList<>();
        arraybuildings.addAll(Arrays.asList(getResources().getStringArray(R.array.my_buildings)));
        adapter = new ArrayAdapter<String>(
                MainActivity.this,
                android.R.layout.simple_list_item_1,
                (List<String>) arraybuildings
        );
        search_buildings.setAdapter(adapter);
        // add on click for each Item by names and set the right pic
        // add pics that will go hand by hand with the Items name
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.search_menu, menu);
        MenuItem item = menu.findItem(R.id.search_buildings);
        SearchView searchView = (SearchView)item.getActionView();

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String s) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String s) {
                adapter.getFilter().filter(s);
                return false;
            }
        });
return super.onCreateOptionsMenu(menu);
    }
}

Main XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="horizontal">

   <ListView
       android:id="@+id/search_buildings"
       android:layout_width="match_parent"
       android:layout_height="422dp"
       android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" />

   <ImageView
       android:id="@+id/b1"
       android:layout_width="294dp"
       android:layout_height="wrap_content"
       android:layout_gravity="top"
       android:layout_marginLeft="-350dp"
       android:layout_marginTop="450dp"
       android:visibility="invisible"
       app:srcCompat="@mipmap/a1" />

   <ImageView
       android:id="@+id/b2"
       android:layout_width="294dp"
       android:layout_height="wrap_content"
       android:layout_gravity="top"
       android:layout_marginLeft="-294dp"
       android:layout_marginTop="450dp"
       android:visibility="invisible"
       app:srcCompat="@mipmap/a2" />

   <ImageView
       android:id="@+id/b3"
       android:layout_width="294dp"
       android:layout_height="wrap_content"
       android:layout_gravity="top"
       android:layout_marginLeft="-294dp"
       android:layout_marginTop="450dp"
       android:visibility="invisible"
       app:srcCompat="@mipmap/a3" />

</LinearLayout>

String XML:

<resources>
    <string name="app_name">Building</string>

    <string-array name="my_buildings">
        <item>number1</item>
        <item>number2</item>
        <item>number3</item>
    </string-array>


</resources>

Hope you can help me!

Thank you!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨离汐 2025-01-24 21:00:19

也许您忘记将主要活动设置为清单中的发射器活动
在主活动标签中将其添加到subtest.xml中

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

Maybe you forget to set the Main Activity as the launcher Activity in the manifest
add this in manifest.xml in the Main Activity tag

> <intent-filter>
>                 <action android:name="android.intent.action.MAIN" />
> 
>                 <category android:name="android.intent.category.LAUNCHER" />
>             </intent-filter>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文