みなさん、前もって申し訳ありませんが、この質問に対する答えを必死に探していました。私は理論的に私が使用することになっていることを知っています
i.putExtra("jsonArray", jArray.toString());
私の意図では、解決できないか、エラーが発生しています。
人の名前と配列からの ID (クエリからの ID と名前) を渡そうとしています。それを渡して、次のアクティビティの次のクエリでその ID を使用できるようにします。
Person resultRow = new Person();
//set that person's attributes
resultRow.id = json_data.getString("id");
resultRow.icon = json_data.getString("birthday");
resultRow.name = json_data.getString("name");
resultRow.address = json_data.getString("address");
resultRow.city = json_data.getString("city");
//this is our arrayList object, we add our Person object to it
arrayOfWebData.add(resultRow);
}
}
catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
//get our listview
ListView myListView = (ListView)findViewById(R.id.myListView);
//we initialize our fancy adapter object, we already declared it above
//in the class definition
aa=new FancyAdapter();
// here we set the adapter, this turns it on
myListView.setAdapter(aa);
myListView.setOnItemClickListener(onListClick);
}
catch (Exception e)
{
// this is the line of code that sends a real error message to the log
Log.e("ERROR", "ERROR IN CODE: " + e.toString());
// this is the line that prints out the location in
// the code where the error occurred.
e.printStackTrace();
}
}
// here is where the magic begins
//we extend our ArrayAdapter, and use it to create custom views
//as well as execute other more complicated functions
//this time, our ArrayAdapter is an array of Persons, instead of strings like in other tutorials
class FancyAdapter extends ArrayAdapter<Person> {
FancyAdapter() {
super(ListActivity.this, android.R.layout.simple_list_item_1, arrayOfWebData);
}
public View getView(int position, View convertView,
ViewGroup parent) {
ViewHolder holder;
//we call an if statement on our view that is passed in,
//to see if it has been recycled or not. if it has been recycled,
//then it already exists and we do not need to call the inflater function
//this saves us A HUGE AMOUNT OF RESOURCES AND PROCESSING
//this is the proper way to do it
if (convertView==null) {
LayoutInflater inflater=getLayoutInflater();
convertView=inflater.inflate(R.layout.row, null);
//here is something new. we are using a class called a view holder
holder=new ViewHolder(convertView);
//we are using that class to cache the result of the findViewById function
//which we then store in a tag on the view
convertView.setTag(holder);
}
else {
holder=(ViewHolder)convertView.getTag();
}
holder.populateFrom(arrayOfWebData.get(position));
return(convertView);
}
}
class ViewHolder {
public TextView name=null;
public TextView address=null;
public TextView icon=null;
ViewHolder(View row) {
name=(TextView)row.findViewById(R.id.name);
address=(TextView)row.findViewById(R.id.birthday);
birthday=(TextView)row.findViewById(R.id.favorite_color);
}
//notice we had to change our populate from to take an arguement of type person
void populateFrom(Person r) {
name.setText(r.name);
address.setText(r.address);
icon.setText(r.birthday);
}
}
private AdapterView.OnItemClickListener onListClick=new android.widget.AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i= new Intent(ListActivity.this, bar.class);
i.putExtra("jsonArray", Person(name).toString());
startActivity(i);
}
};
}