0
我已經從Json服務器在ListView中的數據顯示在片段 ,但是當我點擊ListView中的每一行時,它會打開一個新的空白活動,但我想在那個Blank活動中顯示ListView的每行數據,如Title,Description和image?那麼如何從Fragment ListView中獲得該活動(空白活動)? 我傳遞意圖方法的數據,但沒有得到? 這是NewsAdapter的News_Fragment如何獲取標題,描述,圖像從JSON服務器使用Volley
public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.MyViewHolder> {
private List<News> newsList;
private Context context;
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView title;
public ImageView image,nextArrowimage;
public TextView desc;
public MyViewHolder(View view) {
super(view);
title = (TextView) view.findViewById(R.id.News_title);
image = (ImageView) view.findViewById(R.id.News_imageView);
nextArrowimage = (ImageView)view.findViewById(R.id.news_NextArrow);
desc = (TextView) view.findViewById(R.id.News_desc);
}
}
public NewsAdapter(List<News> newsList,Context context) {
this.newsList = newsList;
this.context = context;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.news_list_row, parent, false);
MyViewHolder holder = new MyViewHolder(itemView);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
final News news = newsList.get(position);
holder.title.setText(news.getTitle());
//holder.image.setImageResource(Integer.parseInt(news.getImage()));
context = holder.image.getContext();
holder.nextArrowimage.setImageResource(R.drawable.nextbutton);
//Picasso.with(context).load("https://www.simplifiedcoding.net/wp-content/uploads/2015/10/advertise.png").resize(100,100).into(holder.image);
Picasso.with(context).load("http://bitstobyte.in/upload/"+news.getImage()).placeholder(R.drawable.ic_favorite_white_24dp).error(R.drawable.ic_map_24dp).resize(100,100).into(holder.image);
//Picasso.with(context).load("http://bitstobyte.in/upload/"+ news.getImage()).resize(100,100).into(holder.image);
holder.desc.setText(news.getDesc().trim());
holder.image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView title = (TextView)v.findViewById(R.id.News_title);
TextView desc = (TextView)v.findViewById(R.id.News_desc);
String str = title.getEditableText().toString().trim();
Intent intent = new Intent(context.getApplicationContext(), News_Activity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.getApplicationContext().startActivity(intent);
intent.putExtra(str,"title");
Toast.makeText(context, "You Clicked " + newsList.get(position), Toast.LENGTH_LONG).show();
}
});
}
@Override
public int getItemCount() {
return newsList.size();
}
}
因此,當從ListView中選擇一個項目時,您將開始另一個活動, h擁有碎片? –
將數據傳遞給'Intent'。 – earthw0rmjim
如何在Intent中傳遞數據? plz給我充分說明或示例代碼 –