Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Simple GridView that displays text in the grids
    text
    copied!<p>I'm following the example on the android tutorial about the GridView, but instead of showing image, i want to just simple show some text using a TextView. it turns out seems to be harder than i thought. it might seems like this is totally unnecessary and it doesn't have a valid use case, but i'm trying this out to just get myself familiar with the sdk. </p> <p>so my code is pretty much the same as the GridView example in <a href="http://developer.android.com/guide/tutorials/views/hello-gridview.html" rel="nofollow noreferrer">http://developer.android.com/guide/tutorials/views/hello-gridview.html</a>, but instead of using a ImageAdapter, i created a dummy adapter like following: </p> <pre><code>public class MyAdapter extends BaseAdapter { private Context context; private String[] texts = {"aaa", "bbb", "ccc", "ddd", "eee", "fff", "eee", "hhh", "iii"}; public MyAdapter(Context context) { this.context = context; } public int getCount() { return 9; } public Object getItem(int position) { return null; } public long getItemId(int position) { return 0; } public View getView(int position, View convertView, ViewGroup parent) { TextView tv; if (convertView == null) { tv = new TextView(context); tv.setLayoutParams(new GridView.LayoutParams(85, 85)); } else { tv = (TextView) convertView; } tv.setText(texts[position]); return tv; } } </code></pre> <p>it all seems valid to me, but running this gives me nothing on the screen. and there's no error message. there are some selectable/clickable (invisible) blocks if i click them, but the text is obvious not shown. i wonder is my layout doesn't have the android:text causing this problem? or anything else?</p> <p>any feedback will be appreciated and thanks for your help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload