这是我的代码:
public class CustomGridAdapter extends BaseAdapter{
Context ctx;
String [] items ={"72","58","67","77","90"} ; //Can be images or video or any other content
String [] stuff = {"bus to town ","Bus to north","Bus to west","Bus to east","Bus out"};
public CustomGridAdapter(Context c) {
ctx = c;
}
@Override
public int getCount() {
return items.length;
}
@Override
public Object getItem(int position) {
return items[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView tv = new TextView(ctx);
TextView tv2 = new TextView(ctx);
tv.setText(String.valueOf(items[position]));
tv2.setText(String.valueOf(stuff[position]));
return tv;
}
}
需要帮助试图找出如何在电视下方显示tv2。 有什么建议吗?
答案 0 :(得分:0)
您需要创建一个垂直的LinearLayout:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout layout = new LinearLayout(ctx);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
TextView tv = new TextView(ctx);
TextView tv2 = new TextView(ctx);
tv.setLayoutParams(lparams);
tv2.setLayoutParams(lparams);
tv.setText(String.valueOf(items[position]));
tv2.setText(String.valueOf(stuff[position]));
layout.addView(tv);
layout.addView(tv2);
return layout;
}