【发布时间】:2014-07-17 21:00:41
【问题描述】:
我想制作2个相同长度的ArrayList<Strings>s,像这样出现在1个ListView中
字 1 是一个 TextView,应该填充 1 ArrayList<String>,字 2 是另一个 TextView,应该填充不同的 ArrayList<String>
*这些是 TextViews,不是 Buttons
我的ArrayAdaptor 应该是什么样的?
如果这是重复的,请给我一个链接。
CustomArrayAdapter.java 两边都显示相同的ArrayList<String>(不是我需要的)
public class CustomArrayAdapter extends BaseAdapter {
Context context;
private ArrayList<String> words1;
private ArrayList<String> words2;
public CustomArrayAdapter(Context context, ArrayList<String> words1, ArrayList<String> words2) {
this.words1 = words1;
this.generates = words2;
this.context = context;
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.list_item, null);
}
String a = (String) getItem(position);
String b = (String) getItem(position);
TextView tv1 = (TextView) v.findViewById(R.id.rhymed_word);
TextView tv2 = (TextView) v.findViewById(R.id.generated_word);
tv1.setText(a);
tv2.setText(b);
return v;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return words1.size();
}
@Override
public Object getItem(int position) {
if (position >= words1.size())
return words2.get(position);
return words1.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}
【问题讨论】:
-
我不确定我是否理解这个问题,您能详细说明一下吗?您是否只希望一个 button.setText() 来自一个 ArrayList 而另一个 button2.setText() 来自另一个 ArrayList?...因为该描述本身就是一种答案...或者他们只是文本视图。它们看起来像按钮,但无论哪种方式都应该是一样的。
-
请查看我对帖子的更改。谢谢
-
对,但是我的第一个问题呢?例如,您是否希望左侧的 TextView 来自一个 ArrayList
而右侧的 TextView 来自每一行的不同 ArrayList ?你有 xml 或任何代码,或者你只是想要一个起点? -
添加了一些输出奇怪的代码。
-
好的,我看到了困境。 getView() 中的位置是项目所在的 listView 的位置。我会发布一些代码
标签: android string android-listview arraylist android-arrayadapter