2013-03-19 46 views
1

我想創建一個名稱列表視圖。點擊每個名字會給我不同的等級。採取數據庫 所有名稱和等級ARA和存儲到它是通過活動,意圖通過JSON格式:如何處理ArrayListAdapter的onListItemClick內的項目?

public class StudentList extends ListActivity { 
public void onCreate(Bundle icicle) { 
super.onCreate(icicle); 

/**get the intent*/ 
Intent studentIntent = getIntent(); 

/**retrieve the string extra passed*/ 
ArrayList<String> nameRecd = studentIntent.getStringArrayListExtra("name"); 
ArrayList<String> gradeRecd = studentIntent.getStringArrayListExtra("grade"); 
try { 
    JSONArray jsonData = new JSONArray(getIntent().getStringExtra("data")); 
    Log.i("json review:", "Check out my JSON, looks like his JMother"); 

    ArrayAdapter<String> adapter = new ArrayAdapter<String> 
    (this, android.R.layout.simple_list_item_1, nameRecd); 
    setListAdapter(adapter); 


} catch (JSONException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 

}

@Override 
protected void onListItemClick(ListView l, View v, int position, long id) { 
String item = (String) getListAdapter().getItem(position); 
int pos = position; 

Toast.makeText(this, item + " selected" + "Grade:" , Toast.LENGTH_LONG).show(); 
} 

}

所以我想對於每一個選擇的名稱能夠爲同一職位的其他職位進行吐司或處理,以便我可以爲特定學生建立某種形象,並能夠通過點擊學生姓名來訪問它!

+1

我沒有得到你有什麼確切的問題:) – agamov 2013-03-19 15:51:03

回答

0

問題解決了啓動內部onListItemClick的sameintent ...

@Override 
protected void onListItemClick(ListView l, View v, int position, long id) { 
String item = (String) getListAdapter().getItem(position); 

/**get the intent*/ 
Intent studentIntent = getIntent(); 

/**retrieve the data extra passed*/ 
ArrayList<String> names = new ArrayList<String>(); 
ArrayList<String> grades = new ArrayList<String>(); 
JSONObject json_data = new JSONObject(); 
try { 
    JSONArray jARR = new JSONArray(getIntent().getStringExtra("data")); 
    Log.i("json review:", "Check out my JSON, looks like his JMother"); 
    for(int i=0;i<jARR.length();i++){ 
     json_data = jARR.getJSONObject(i); 
     names.add((json_data.getString("name"))) ; 
     grades.add((json_data.getString("grade"))) ; 

    } 



} catch (JSONException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 
相關問題