データベース値をListviewに表示しようとしていますが、要素の位置を手動で設定しています(if(position == 0){})。しかし、これらの要素をID、名前、モバイルに応じて表示したいとします(つまり、第1要素アクティビティでこれらのパラメータを解析して2番目のパラメータが適切な値を保持できるようにするなど)。 これをどのように実行できますか?位置に応じてListViewの値を取得する方法は?
List.java
protected void showList(){
try {
JSONObject jsonObj = new JSONObject(myJSON);
peoples = jsonObj.getJSONArray(TAG_RESULTS);
for(int i=0;i<peoples.length();i++){
JSONObject c = peoples.getJSONObject(i);
String id = c.getString(TAG_ID);
String name = c.getString(TAG_NAME);
String mobile = c.getString(TAG_MOB);
HashMap<String,String> persons = new HashMap<String,String>();
persons.put(TAG_ID,id);
persons.put(TAG_NAME,name);
persons.put(TAG_MOB,mobile);
personList.add(persons);
}
ListAdapter adapter = new SimpleAdapter(
User_List.this, personList, R.layout.list_item,
new String[]{TAG_ID,TAG_NAME,TAG_MOB},
new int[]{R.id.id, R.id.name, R.id.mobile}
);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(position==0) {
Intent intent = new Intent(User_List.this, MapsActivity.class);
startActivity(intent);
}
}
});
} catch (JSONException e) {
e.printStackTrace();
}
は、次のアクティビティは同じですか? –
@Satish Silveri ..yes! –