0
ListView에서 작업하고 있습니다. 나중에 선택한 요소를 사용하고 재고를 확보하고 싶습니다.ListView에서 체크 된 항목 가져 오기 및 사용
그것은 기본이 될 수 있지만 초보자로서, 난 정말 어떻게 처리 해야할지 모르겠어 .. 여기
내 목록의 모양, 그리고 관련 자바 코드 무엇 :http://i.stack.imgur.com/MgKq9.jpg
public class PizzaActivity extends DashboardActivity {
/** Called when the activity is first created. */
// HashMap arraList taking objects
private ArrayList <HashMap<String, Object>> myIng;
private static final String INGREDIENT = "ingnom";
private static final String PRIX = "ingprix";
private static final String IMAGE = "iconfromraw";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_f2);
ListView listView = (ListView)findViewById(R.id.list);
myIng = new ArrayList<HashMap<String,Object>>();
HashMap<String, Object> hm;
// Créée une nouvelle HashMap et définis ses élements
hm = new HashMap<String, Object>();
hm.put(IMAGE, R.drawable.mozza);
hm.put(INGREDIENT, "Mozzarella");
hm.put(PRIX, "Prix : 0.60€");
// Ajoute la HashMap créée à la liste
myIng.add(hm);
hm = new HashMap<String, Object>();
hm.put(IMAGE, R.drawable.emmental);
hm.put(INGREDIENT, "Emmental");
hm.put(PRIX, "Prix : 0.50€");
myIng.add(hm);
hm = new HashMap<String, Object>();
hm.put(INGREDIENT, "Chèvre");
hm.put(PRIX, "Prix : 0.75€");
hm.put(IMAGE, R.drawable.chevre);
myIng.add(hm);
hm = new HashMap<String, Object>();
hm.put(INGREDIENT, "Roquefort");
hm.put(PRIX, "Prix : 0.75€");
hm.put(IMAGE, R.drawable.roquefort);
myIng.add(hm);
// Définis un SimpleAdapter et lie les valeurs aux lignes de la vue view R.layout.listview
SimpleAdapter adapter = new SimpleAdapter(this, myIng, R.layout.listview,
new String[]{IMAGE,INGREDIENT,PRIX}, new int[]{R.id.img,R.id.text1, R.id.text2});
listView.setAdapter(adapter);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
}
어떤 조언을 멋진 것 :
감사합니다!
감사 같아야합니다, 나는 그것을 확인. 내 목록의 각 요소에는 그림과 가격이 포함되어 있으므로 "모델"클래스에 추가해야합니까? 아니면 다른 곳? – Morgan
세부 사항을 도와 줄 답변을 편집했습니다. – san
다시 한 번 감사드립니다. 어떻게 작동하는지 알기 시작했습니다. "getView"예제에서 "mData"를 정확히 나타내는 것은 무엇인지 이해하지 못합니다. – Morgan