Android 单击GridView中的图像不会显示ListView

Android 单击GridView中的图像不会显示ListView,android,listview,gridview,Android,Listview,Gridview,我已经在我的活动中创建了一个GridView,但是当我在GridView中单击图像时,它应该显示我给出的意图的屏幕,其中我正在显示一些项目的列表,但我没有显示ListView,但是该类中的所有其他Logcat语句正在运行 GridView的代码是 GridLayoutActivity.java public class GridLayoutActivity extends AppCompatActivity{ @Override public void onCreate(Bun

我已经在我的活动中创建了一个GridView,但是当我在GridView中单击图像时,它应该显示我给出的意图的屏幕,其中我正在显示一些项目的列表,但我没有显示ListView,但是该类中的所有其他Logcat语句正在运行

GridView的代码是

GridLayoutActivity.java

public class GridLayoutActivity extends AppCompatActivity{

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

        GridView gridView = (GridView) findViewById(R.id.grid_view);

        // Instance of ImageAdapter Class
        gridView.setAdapter(new GalleryAdapter(this));

        gridView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View v,
                                    int position, long id)
            {


                    Toast.makeText(GridLayoutActivity.this, "" + position,
                            Toast.LENGTH_SHORT).show();
                    Intent i = new Intent(getApplicationContext(), Hindi_SongsActivity.class);
                    startActivity(i);




                /*if(position==1)
                {
                    Intent i = new Intent(getApplicationContext(), English_SongsActivity.class);
                    startActivity(i);
                }
                if(position==2)
                {
                    Intent i = new Intent(getApplicationContext(), Melody_SongsActivity.class);
                    startActivity(i);
                }*/

            }
        });



    }
}
这是我的GridView xml代码

public class GalleryAdapter extends BaseAdapter {
    private Context mContext;

    // Keep all Images in array
    public Integer[] mThumbIds = {
            R.drawable.bollywood1, R.drawable.hollywood1,
            R.drawable.melody

    };

    // Constructor
    public GalleryAdapter(Context c)
    {
        mContext = c;
    }

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

    @Override
    public Object getItem(int position) {
        return mThumbIds[position];
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = new ImageView(mContext);
        imageView.setImageResource(mThumbIds[position]);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setLayoutParams(new GridView.LayoutParams(300, 300));
        return imageView;
    }

}
<?xml version="1.0" encoding="utf-8"?>
<GridView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/grid_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:numColumns="auto_fit"
    android:columnWidth="150dp"
    android:horizontalSpacing="10dp"
    android:verticalSpacing="20dp"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:gravity="center"
    android:background="@drawable/my_subtle_pattern"
    android:stretchMode="columnWidth" >
</GridView>

ListView的代码是

public class Hindi_SongsActivity extends AppCompatActivity
{
    private ListView mlistview;
    private Firebase mRef;
    private ArrayList<String> titles=new ArrayList<String>();
    private String TAG=English_SongsActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.hindi_songs_list);
        mlistview = (ListView) findViewById(R.id.hindi_songs);

   DatabaseReference hindi= FirebaseDatabase.getInstance().getReference().child("Vikas").child("Music").child("Hindi");
        final ArrayAdapter<String> arrayAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,titles);
        mlistview.setAdapter(arrayAdapter);

       hindi.addValueEventListener(new ValueEventListener()
        {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot)
            {
                for(DataSnapshot hindi_songs: dataSnapshot.getChildren())
                {
                    for (DataSnapshot hindi_songs_children : hindi_songs.getChildren())
                    {
                        if (hindi_songs_children.getKey().equals("title"))
                        {
                            Log.d(TAG, "run");
                            String value = hindi_songs_children.getValue().toString();
                            titles.add(value);
                        }

                    }
                }
                Log.d(TAG,"titles"+titles.size());
                arrayAdapter.notifyDataSetChanged();
            }


            @Override
            public void onCancelled(DatabaseError databaseError)
            {


            }
        });
        mlistview.setAdapter(arrayAdapter);
}
}
公共类印地语歌曲活动扩展了AppCompative活动
{
私有列表视图;
私人消防基地;
私有ArrayList titles=新ArrayList();
private String TAG=English_SongsActivity.class.getSimpleName();
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.hindi歌曲列表);
mlistview=(ListView)findViewById(R.id.hindi_歌曲);
DatabaseReference印地语=FirebaseDatabase.getInstance().getReference().child(“Vikas”).child(“音乐”).child(“印地语”);
final ArrayAdapter ArrayAdapter=新的ArrayAdapter(这是android.R.layout.simple\u list\u item\u 1,titles);
setAdapter(arrayAdapter);
印地语.addValueEventListener(新的ValueEventListener()
{
@凌驾
公共void onDataChange(DataSnapshot DataSnapshot)
{
用于(DataSnapshot印地语歌曲:DataSnapshot.getChildren())
{
for(DataSnapshot印地语歌曲儿童:印地语歌曲.getChildren())
{
if(印地语歌曲\u children.getKey().equals(“title”))
{
Log.d(标记“运行”);
String value=hindi_songs_children.getValue().toString();
标题.增加(价值);
}
}
}
Log.d(标记“titles”+titles.size());
arrayAdapter.notifyDataSetChanged();
}
@凌驾
已取消的公共void(DatabaseError DatabaseError)
{
}
});
setAdapter(arrayAdapter);
}
}
以及xml列表视图

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">



    <ListView
        android:id="@+id/hindi_songs"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/my_subtle_pattern"
        android:scrollbarStyle="insideOverlay">

    </ListView>

</LinearLayout>

这是我在GridView中单击图像时得到的logcat

05-01 20:54:53.229 27182-27247/com.dekhoapp.android.app.base I/OpenGLRenderer:初始化EGL,版本1.4 05-01 20:54:53.330 27182-27234/com.dekhoapp.android.app.base D/FA:连接到远程服务 05-01 20:54:53.330 27182-27234/com.dekhoapp.android.app.base V/FA:处理排队服务任务:2 05-01 20:54:58.373 27182-27234/com.dekhoapp.android.app.base V/FA:不活动,正在断开与服务的连接 05-01 20:55:00.022 27182-27234/com.dekhoapp.android.app.base V/FA:记录用户参与度,ms:6863 05-01 20:55:00.023 27182-27234/com.dekhoapp.android.app.base V/FA:使用测量服务 05-01 20:55:00.023 27182-27234/com.dekhoapp.android.app.base V/FA:连接到远程服务 05-01 20:55:00.027 27182-27234/com.dekhoapp.android.app.base V/FA:活动暂停,时间:94963992 05-01 20:55:00.037 27182-27234/com.dekhoapp.android.app.base I/FA:找不到标记管理器,因此不会使用 05-01 20:55:00.050 27182-27234/com.dekhoapp.android.app.base D/FA:日志事件(FE):_e,Bundle[{{u o=auto,_et=6863,_sc=GridLayoutActivity,_si=5934656916561625555}] 05-01 20:55:00.090 27182-27234/com.dekhoapp.android.app.base V/FA:使用测量服务 05-01 20:55:00.090 27182-27234/com.dekhoapp.android.app.base V/FA:连接尝试已在进行中 05-01 20:55:00.137 27182-27182/com.dekhoapp.android.app.base V/FA:onActivityCreated 05-01 20:55:00.266 27182-27182/com.dekhoapp.android.app.base I/DynamiteModule:考虑本地模块com.google.android.gms.firebase_数据库:4和远程模块com.google.android.gms.firebase_数据库:5 05-01 20:55:00.266 27182-27182/com.dekhoapp.android.app.base I/DynamiteModule:com.google.android.gms.firebase_数据库的选定远程版本,版本>=5 05-01 20:55:00.289 27182-27234/com.dekhoapp.android.app.base V/FA:使用测量服务 05-01 20:55:00.289 27182-27234/com.dekhoapp.android.app.base V/FA:连接尝试已在进行中 05-01 20:55:00.289 27182-27234/com.dekhoapp.android.app.base V/FA:活动已恢复,时间:94964259 05-01 20:55:00.349 27182-27234/com.dekhoapp.android.app.base D/FA:已连接到远程服务 05-01 20:55:00.349 27182-27234/com.dekhoapp.android.app.base V/FA:处理排队服务任务:3 05-01 20:55:00.441 27182-27247/com.dekhoapp.android.app.base D/OpenGLRenderer:0x5574c703d0(GridView)上带句柄0x5574c7e860的endAllStagingAnimators 05-01 20:55:05.445 27182-27234/com.dekhoapp.android.app.base V/FA:不活动,正在断开与服务的连接 05-01 20:55:07.273 27182-27182/com.dekhoapp.android.app.base D/English_SongsActivity:run 05-01 20:55:07.274 27182-27182/com.dekhoapp.android.app.base D/English_SongsActivity:run 05-01 20:55:07.274 27182-27182/com.dekhoapp.android.app.base D/English_SongsActivity:run 05-01 20:55:07.274 27182-27182/com.dekhoapp.android.app.base D/English_SongsActivity:run 05-01 20:55:07.274 27182-27182/com.dekhoapp.android.app.base D/English_SongsActivity:run
05-01 20:55:07.274 27182-27182/com.dekhoapp.android.app.base D/English_SongsActivity:titles5

那么你的意思是说你的“印地语歌曲活动.class”活动是在你有列表视图的地方启动的。但是你在那里看不到ListView???是的,这就是发生的事情,如果我单独运行ListView活动,那么它将显示listok。请发布ListView适配器的代码以及在活动中设置ListView适配器的代码。让我看看哪里出错了我已经更新了代码