我想创建一个带有名称的列表视图。点击每个名字会给我不同的等级。所有名称和等级都由数据库获取并存储为 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();
}
}
因此,我希望每个选定的姓名都能够敬酒或处理同一职位的其他成绩,这样我就可以为特定学生建立某种个人资料,并能够通过单击学生姓名来访问它!