我實現了一個自定義適配器來填充自定義ListView
與一個image
和2 TextField
。現在我想要做的是添加新的行動態滾動列表。何可以做到這一點?將數據添加到自定義列表視圖滾動列表
這是適配器
public class CustomListAdapter extends ArrayAdapter<String> {
private final Activity context;
private final String[] itemname;
private final Integer[] imgid;
private final String[] questions;
public CustomListAdapter(Activity context, String[] itemname, Integer[] imgid, String[] questions) {
super(context, R.layout.mylist, itemname);
// TODO Auto-generated constructor stub
this.context = context;
this.itemname = itemname;
this.imgid = imgid;
this.questions=questions;
}
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.mylist, null, true);
rowView.setPadding(0,10,0,10);
TextView txtTitle = (TextView) rowView.findViewById(R.id.nameList);
txtTitle.setTextColor(Color.BLACK);
ImageView imageView = (ImageView) rowView.findViewById(R.id.imgList);
TextView extratxt = (TextView) rowView.findViewById(R.id.question);
txtTitle.setText(itemname[position]);
imageView.setImageDrawable(new RoundImage(BitmapFactory.decodeResource(context.getResources(), imgid[position])));
//imageView.setImageResource(imgid[position]);
extratxt.setText(questions[position]);
return rowView;
};
}
這是在列表中位於
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedBundle) {
this.adapter=new CustomListAdapter(getActivity(), itemname, imgid, questions);
list=(ListView)firstAccessView.findViewById(R.id.list);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//stuff
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
String Slecteditem= itemname[+position];
Toast.makeText(getActivity().getApplicationContext(), Slecteditem, Toast.LENGTH_SHORT).show();
}
});
}
,我怎麼能追加我的數據? – Bella
對你的數據做一些分頁..分數據。那麼你可以使用collection來追加數據。然後通知您的適配器。 – Android
如果我的適配器擴展了ArrayAdapter,我該如何追加數據。當我嘗試在裏面的方法裏面做myadapter.addAll()時,我可以只放入String,而不是我想把更多的 –
Bella