在这种方法中我收到ArrayList
OkHttpHandler handler = new OkHttpHandler(MainActivity.this,new OkHttpHandler.MyInterface() {
@Override
public void myMethod(ArrayList result) {
Toast.makeText(MainActivity.this, "Connection Succesful",
Toast.LENGTH_LONG).show();
GridViewAdapter adapter = new GridViewAdapter(getApplicationContext(), R.layout.grid_item_layout, result);
我想要的是将这个数组列表发送到 gridiview 中的另一个活动。当用户单击 gridview 中的图像时,我想将 ArrayList 中的该图像发送到下一个活动。如何做到这一点>
这是网格视图
holder.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("OnImageButton", "Clicked");
Intent intnt =new Intent(mcontext, SingleViewActivity.class);
//intnt.putExtra("Contact_list", item);
mcontext.startActivity(intnt) ; //This line raises error
Toast.makeText(mcontext, "intent",
Toast.LENGTH_LONG).show();
}
});
我尝试了 parcable,但它不起作用,因为我只想将数据发送到另一个活动,我不想启动新活动
这就是我尝试过的
Listitem = new ArrayList<Listitem>();
for(int i=0;i<peoples.length();i++){
JSONObject c = peoples.getJSONObject(i);
// String id ="2";
String id= c.getString("ID");
String url = c.getString("URL");
Log.d("Id: ", id);
int intid = 0;
Student student = new Student(c.getString("ID"),
"hhe",
c.getString("URL")
);
Intent intent = new Intent(mContext,SingleViewActivity.class);
// Passing data as a parecelable object to StudentViewActivity
intent.putExtra("student",student);
// Opening the activity
mContext.startActivity(intent);
在这个方法中,我通过ArrayList
到另一项活动
try {
JSONObject jsonObj = new JSONObject(myJSON);
peoples = jsonObj.getJSONArray("result");
System.out.println(peoples.length());
Listitem = new ArrayList<Listitem>();
for(int i=0;i<peoples.length();i++){
JSONObject c = peoples.getJSONObject(i);
String id= c.getString("ID");
String url = c.getString("URL");
Log.d("Id: ", id);
int intid = 0;
try {
intid = Integer.parseInt(id.toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
DatabaseHandler db = new DatabaseHandler(mContext);
Log.d("Insert: ", "Inserting ..");
db.addObjects(new Objects(intid,"Image1", url, "IMAGES", "Funny"));
Listitem.add(new Listitem(id,url));
Log.e("d", "ppppp");
System.out.println(Listitem);
}
if (mListener != null)
mListener.myMethod(Listitem);