我正在关注本教程android custom listview with image and text using volley(原始项目文件可以找到here),我修改了代码,以便在用户点击某个项目时显示有关单个项目的更多信息。
这是....
// Parsing json
for (int i = 0; i < response.length(); i++) {
try {
movie.setTitle(obj.getString("title"));
// this is the image path in the json file
movie.setThumbnailUrl(obj.getString("image"));
......
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String _movieTitle = ((TextView) view.findViewById(R.id.title)).getText().toString();
Intent myIntent = new Intent (MainActivity.this, MoreInfoActivity.class);
// send movie title
myIntent.putExtra("title", _movieTitle) ;
// the problem is here, I cannot send the image path
//myIntent.putExtra("image", R.id.image) ;
startActivity(myIntent) ;
}
});
custom adapter
if (imageLoader == null)
imageLoader = AppController.getInstance().getImageLoader();
NetworkImageView thumbNail = (NetworkImageView) convertView.findViewById(R.id.thumbnail);
TextView title = (TextView) convertView.findViewById(R.id.title);
// getting movie data for the row
Movie m = movieItems.get(position);
// thumbnail image
thumbNail.setImageUrl(m.getThumbnailUrl(), imageLoader);
内容:
moredetailsactivity.java
我的public class moredetailsactivity extends Activity {
private TextView title, image;
private String _title,_rating,_image;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.movie_details);
title = (TextView) findViewById(R.id.title);
image = (TextView) findViewById(R.id.image);
Intent i = getIntent();
if (i.getExtras() != null) {
_title = (String) i.getExtras().get("title");
_image = (String) i.getExtras().get("image");
}
title.setText(_title);
.....
}
:
mainactivity
我想在moredetailsactivity
的{{1}}中显示相同的缩略图。
这会显示main_activity.xml
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/thumbnail"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_marginRight="8dp" />
但相同的代码在more_details.xml
上没有显示任何内容。
答案 0 :(得分:0)
private JSONArray movieList;
.......
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String _movieTitle = ((TextView) view.findViewById(R.id.title)).getText().toString();
Intent myIntent = new Intent (MainActivity.this, MoreInfoActivity.class);
String image = movieList.get(position).getString("image");
// send movie title
myIntent.putExtra("title", _movieTitle) ;
myIntent.putExtra("image", _movieTitle) ;
// the problem is here, I cannot send the image path
//myIntent.putExtra("image", R.id.image) ;
startActivity(myIntent) ;
}
});