我想创建一个带名字的列表视图。点击每个名字会给我不同的成绩。 数据库采用的所有名称和等级ara,存储为json格式,通过intents:
传递活动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();
}
}
所以我希望每个选定的名字能够烘烤或处理相同位置的其他等级,这样我就可以为特定学生建立某种形式,并且可以通过点击学生姓名来访问它!
答案 0 :(得分: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();
}