我正在实现列表视图,我有用户 BaseAdapter 类。我正在尝试从数组列表中在持有者的文本视图字段中设置文本,但没有任何成功。问题出在 getView 方法的HashMap<String, ArrayList<String>> map = list.get(position);
holder.txtFirst.setText(map.get(FIRST_COLUMN).toString());
一部分。
编辑:
我的主要活动类(postExecute 方法),我在其中设置列表适配器类的键和值。代码如下:
protected void onPostExecute(ArrayList<ArrayList<String>> result) {
ArrayList<String> conceptID = new ArrayList<String>(result.get(0));
ArrayList<String> conceptDesc = new ArrayList<String>(result.get(1));
listForSearchConcepts = new ArrayList<HashMap<String,ArrayList<String>>>();
HashMap<String, ArrayList<String>> temp = new HashMap<String,ArrayList<String>>();
temp.put(FIRST_COLUMN,conceptID);
listForSearchConcepts.add(temp);
temp.put(SECOND_COLUMN,conceptDesc);
listForSearchConcepts.add(temp);
listviewAdapter adapter = new listviewAdapter(MainActivity.this, listForSearchConcepts);
listView.setAdapter(adapter);
}`
但是下面是我的适配器类代码:
public class listviewAdapter extends BaseAdapter
{
public ArrayList< HashMap < String,ArrayList < String > > > list;
Activity activity;
public listviewAdapter(Activity activity, ArrayList<HashMap<String,ArrayList<String>>> listForSearchConcepts) {
super();
this.activity = activity;
this.list = listForSearchConcepts;
}
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
private class ViewHolder {
TextView txtFirst;
TextView txtSecond;
TextView txtThird;
TextView txtFourth;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
ViewHolder holder;
LayoutInflater inflater = activity.getLayoutInflater();
if (convertView == null)
{
convertView = inflater.inflate(R.layout.listview_row, null);
holder = new ViewHolder();
holder.txtFirst = (TextView) convertView.findViewById(R.id.FirstText);
holder.txtSecond = (TextView) convertView.findViewById(R.id.SecondText);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
HashMap<String, ArrayList<String>> map = list.get(position);
holder.txtFirst.setText(map.get(FIRST_COLUMN).toString());
//holder.txtSecond.setText(map.get(SECOND_COLUMN).get(1));
//holder.txtThird.setText(map.get(THIRD_COLUMN));
//holder.txtFourth.setText(map.get(FOURTH_COLUMN));
return convertView;
}
}
我还附上了我实际运行应用程序的屏幕截图:
有什么建议吗?
谢谢