如何显示ListView中的值

时间:2014-09-28 07:01:14

标签: android list listview android-listview

我想显示所选ListView的数据 我有列表数据

public static List<Object>getDataList() throws ParseException {         
    List<Object> list = new LinkedList<Object>();              
    for(int j=0;j<rankVaccine.size();j++){
        list.add(new DateOfVaccine("Month " + rankVaccine.get(j).getVRank()));
        for(int i = 0;i<vac.size();i++){
            if(vac.get(i).getVRank()==rankVaccine.get(j).getVRank()){
                list.add(new EntityVeccine(vac.get(i).getVDname()));
            }
        }
    }                        
    return list;
}

我想在listView上显示选择疫苗的疫苗名称

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    BabyVac = new BabyVaccine();
    vaccine = new EntityVeccine(null);
    BabyID = BabyVac.BabyID;

    View view = inflater.inflate(R.layout.baby_vaccine_fragment, container, false);
    final ListView listView = (ListView)view.findViewById(R.id.vaccine_list);               

    try {
        listView.setAdapter(new BabyVaccineAdapter(getActivity(), BabyVac.getDataList()));
        listView.setOnItemClickListener(new OnItemClickListener() {             
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {                          
                Toast.makeText(getActivity(), "position"+listView.getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show();                    
                Intent goNext = new Intent().setClass(getActivity(), BabyVaccineInsert.class);
                goNext.putExtra("idBaby", BabyID);
                startActivity(goNext);
            }
        });

    } catch (ParseException e) {
        e.printStackTrace();
    }
    return view;        
}

去了我的Toast数据输出是Entity.EntityVaccine@223b5cc8。

但我确实想要名字疫苗。

0 个答案:

没有答案