1

我想创建一个带有名称的列表视图。点击每个名字会给我不同的等级。所有名称和等级都由数据库获取并存储为 json 格式,该格式通过具有意图的活动传递:

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();
}

}

因此,我希望每个选定的姓名都能够敬酒或处理同一职位的其他成绩,这样我就可以为特定学生建立某种个人资料,并能够通过单击学生姓名来访问它!

4

1 回答 1

0

问题解决了在 onListItemClick 内启动相同的意图...

@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();
}
于 2013-03-20T08:19:50.600 回答