Breaking News

java – Image is visible but text is not visible in ListView-Exceptionshub


I am trying to create a custom layout for list view in android studio. I was able to successfully get image in the in ListView on runtime but wasn’t able to print text in the list view . When i run my program in emulator it runs without any error but it doesn’t show any text it only shows image from drawables.


import android.os.Bundle;
import android.widget.ListView;

public class MainActivity extends AppCompatActivity {
    private final  static String[] names={"A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A",

    protected void onCreate(Bundle savedInstanceState) {
        ListView ls = findViewById((;
        ls.setAdapter(new CustomListAdapter(getApplicationContext(),names,;



    import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomListAdapter extends BaseAdapter {
    private final Context context;
    private final String[] names;
    private final int image;
    private final LayoutInflater layoutInflater;

    public  CustomListAdapter(Context context,String[] names,int image) {

        layoutInflater= (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    public int getCount() {
        return names.length;

    public Object getItem(int position) {
        return position;

    public long getItemId(int position) {
        return position;

    public View getView(int position, View convertView, ViewGroup parent) {
        View rootview;
        rootview = layoutInflater.inflate(R.layout.list_item_layout, null);
        TextView tv= rootview.findViewById(;
        ImageView iv=rootview.findViewById(;
        return rootview;






How to&Answers:

The issue is in your list_item_layout file. There is an issue with match_parent in your layout try using below code



The problem was caused by the text colour , changing the colour of textview text in list_item_layout resolved the issue.

About rankhawks

Check Also

javascript – Readonly textfield tooltip using jquery

February 22, 2020 Jquery Leave a comment Questions: I am working on a web-app which …

javascript – Saving div innerText directly to database

Questions: I have a simple div with contenteditable and I want to store its value …

jquery – Javascript how to add a click event listener in the body?

Questions: How do i add a click event listener to the body so when i …

yii2 advanced app – How to Run .ics (outlook calender file) using php instead of download or read as a text file?

Questions: I am working on yii2 advanced app where i need to add my events …

jquery – Hide all list items except one when collapsed and show all when expanded in JavaScript

Questions: Suppose I do have a like One Two Three Four Now , I want …

Leave a Reply

Your email address will not be published. Required fields are marked *