如何使用Volley

时间:2016-07-05 11:49:20

标签: android json listview android-fragments

我从ListView中的Json Server获取了数据,显示在片段中 但是当我单击ListView中的每一行时,它将打开一个新的空白活动,但我想在该空白活动中显示ListView每个行数据,如标题,描述和图像?然后如何从Fragment ListView中获取它的活动(空白活动)??? 我从intent方法传递数据但没有得到?? 这是NewsAdapter的Ne​​ws_Fragment

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();
}

}

1 个答案:

答案 0 :(得分:0)

这是将数据从一个活动发送到另一个活动的代码

    startActivity(new Intent(getActivity(),YourActivity.class).putExtra("Title","TileValue").putExtra("Decscription","decriptionValue));

然后您可以在以后的活动中检索:

String title=getIntent().getStringExtra("Title");