当我点击 product1 上的列表时,我得到[product1]
,同样,当我点击 product2 时,我得到了[product2]
,但我想要这个:如果我点击产品 1,然后点击产品 2,输出必须是:[product1, product2]
。
public class MyListFrag extends ListFragment {
Context context;
ListView listView;
List<Content> rowItems;
public static final String[] titles = new String[] { "Product1", "Product2", "product3" };
public static final String[] descriptions = new String[] { "Android", "iphone", "blackberry"};
public void onAttach(Activity activity) {
// TODO Auto-generated method stub
super.onAttach(activity);
this.context = activity.getApplicationContext();
rowItems = new ArrayList<Content>();
for (int i = 0; i < titles.length; i++) {
Content item = new Content( titles[i], descriptions[i]);
rowItems.add(item);
}
setListAdapter(new CustomBaseAdapter(activity.getApplicationContext(), rowItems));
}
public void onListItemClick(ListView l, View view, final int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, view, position, id);
String data1 =rowItems.get(position).getTitle();
System.out.println("Title"+data1);
String data2 =rowItems.get(position).getDescriptio();
System.out.println("Descr"+data1);
ArrayList<String> titleArray = new ArrayList<String>();
TitleArray.add(data1);
ArrayList<String> desArray = new ArrayList<String>();
desArray.add(data2);
System.out.println("Title::::"+titleArray);
System.out.println("descr:::"+desArray);
}
}