【发布时间】:2012-02-14 11:34:03
【问题描述】:
我有一个自定义的ListView 和两个TextViews,我的班级中有两个字符串数组,如何将这两个字符串数组添加为我的ListView 的项目?每个代表一个文本视图。
谢谢。
【问题讨论】:
-
@HirenDabhi 我已经编辑了我的问题,请检查我的问题是否不同。
我有一个自定义的ListView 和两个TextViews,我的班级中有两个字符串数组,如何将这两个字符串数组添加为我的ListView 的项目?每个代表一个文本视图。
谢谢。
【问题讨论】:
我觉得这对你有用,用两个字符串数组调用简单的适配器
public class simleAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater linflater;
private TextView txt_1, txt_2;
private String[] str1;
private String[] str2;
public simleAdapter(Context context, String[] s1, String[] s2) {
mContext = context;
str1 = s1;
str2 = s2;
linflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return str1.length;
}
@Override
public Object getItem(int arg0) {
return str1[arg0];
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = linflater.inflate(R.layout.feed_raw, null);
}
txt_1 = (TextView) convertView.findViewById(R.id.txtlist1);
txt_2 = (TextView) convertView.findViewById(R.id.txtlist2);
txt_1.setText(str1[position]);
txt_2.setText(str2[position]);
return convertView;
}
}
如果您有任何疑问,请告诉我
【讨论】:
在此线程Custom adapter: get item number of clicked item in inflated listview 中查看我的答案。 这应该可以回答您正在尝试做的事情。
【讨论】: