当我点击自定义列表视图中有来自asynctask的数据的项目时,如何获取值,我点击了项目,如何获得来自json格式的特定项目ID的值。
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
progress.dismiss();
try {
JSONObject object= new JSONObject(result);
JSONObject ob= object.getJSONObject("userdetail");
String profile_pic=ob.getString("user_profile_pic");
String name= ob.getString("user_login");
String listing_count=object.getString("listening_count");
String listen= object.getString("listener_count");
String des=ob.getString("user_description");
((App) User_Post.this.getApplication()).setName(name);
((App) User_Post.this.getApplication()).setDesc(des);
((App) User_Post.this.getApplication()).setImg(profile_pic);
if(object.has("posts")){
Log.e("post", "Post entry");
JSONArray posts= object.getJSONArray("posts");
total=posts.length();
Log.e("post", "Post entry"+total);
for(int i=0; i<posts.length();i++){
Post_pojo po= new Post_pojo();
JSONObject json= posts.getJSONObject(i);
a= json.getString("text_post");
**user_post=json.getString("ID").toString();**
po.setText_post(a);
search.add(po);
}
Log.e("result", ""+user_post);
// post.setText(total);
}else{
//post.setText("0");
total=0;
Log.e("post", "Post entry0");
}
Log.e("result", ""+profile_pic);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
URL newurl = new URL(profile_pic);
Bitmap img;
img = BitmapFactory.decodeStream(newurl.openConnection().getInputStream());
profile.setImageBitmap(img);
username.setText(name);
listners.setText(listen);
listings.setText(listing_count);
desc.setText(des);
post.setText(""+total);
Custom_post custom= new Custom_post(getApplicationContext(), R.layout.custom_post, search);
list.setAdapter(custom);
} ///--- Exception---///
}
列表视图点击监听器:
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
TextView user= (TextView)arg1.findViewById(R.id.detail);
list_user_name=user.getText().toString();
Log.e("user name", ""+list_user_name);
us= (TextView)arg1.findViewById(R.id.detail);
Intent in = new Intent(User_Post.this, Teaching.class);
in.putExtra("text", list_user_name);
**in.putExtra("user_post", user_post);**
Log.e("post", ""+user_post);
ActivityStack ac=(ActivityStack)getParent();
ac.startChildActivity("Posts", in);
}
});
}