Skip to content Skip to sidebar Skip to footer

Custom Listview Is Not Showing Up The String

Listview is not showing the string list rather showing only the custom list view text My string declaration n the main String[] Example = new String[] { 'Android Introducti

Solution 1:

Listview is not showing the string list rather showing only the custom list view text

Becuase you are not setting text for TextView in each row of ListView just setting color of row.

so customize getView method and set TextView text from items String Array. see following example for more help: Using an ArrayAdapter with ListView

Solution 2:

You have to declare your CustomAdapter object in Activity As:

CustomAdapterExampleArrayAdapter=newCustomAdapter(this, Example);

    ListViewExampleListView= (ListView)findViewById(R.id.listView);
    ExampleListView.setAdapter(ExampleArrayAdapter);

And Your Adapter Code should be:

publicclassCustomAdapterextendsArrayAdapter{
private LayoutInflater inflater;
private String[] items;
publicCustomAdapter(Activity activity, String[] items){
          super(activity, 0, items);
    inflater = activity.getWindow().getLayoutInflater();
}

@Overridepublic View getView(int position, View convertView, ViewGroup parent){
 Randomrnd=newRandom();

   intcolor= Color.argb(255, rnd.nextInt(256), rnd.nextInt(257), rnd.nextInt(258));

  ViewrowView= inflater.inflate(R.layout.custom_layout, parent, false);
    rowView.setBackgroundColor(color);
TextViewtv= (TextView) rowView .findViewById(R.id.textView1);
tv.setText(items[position]);
    return rowView;


}
}

Post a Comment for "Custom Listview Is Not Showing Up The String"