生成的列表视图仅包含Intent putExtra中的最后一个变量

时间:2016-01-12 16:47:09

标签: java android listview android-intent

我想为putExtra添加ListView中每个生成元素的一些唯一变量。它生成了一个电视节目列表,我想为每个系列添加额外的id,onClick它会产生意图,打开有关系列信息的活动。但它把上一个搜索过的元素的变量放在了下面。 (元素上的名称是正确的,但只有在putExtra中才是最后一个位置的变量)这是我的代码:

class MovieAdapter extends ArrayAdapter {

    private List<MovieModel> movieModelList;
    private int resource;
    private LayoutInflater inflater;
    LinearLayout linear;
    FrameLayout framel;
    Button btn1;
    TextView txv;
    Intent intent;

    private String ide;
    private String name;
    private String overview;
    private String poster_path;
    int pos;

    public MovieAdapter(Context context, int resource, List<MovieModel> objects) {
        super(context, resource, objects);
        movieModelList = objects;
        this.resource = resource;

        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.row, null);
        }
        name = movieModelList.get(position).getName();
        overview = movieModelList.get(position).getOverview();
        ide = movieModelList.get(position).getId() + "";
        poster_path = movieModelList.get(position).getPoster_path();

        pos = position;

        txv = (TextView) convertView.findViewById(R.id.textView2);
        btn1 = (Button) convertView.findViewById(R.id.button2);
        linear = (LinearLayout) convertView.findViewById(R.id.linear);


        txv.setText(name);
        intent = new Intent(MainActivity.this, SerieActivity.class);
    linear.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //Intent intent;
            intent.putExtra("id", ide);
            intent.putExtra("name", name);
            intent.putExtra("overview", overview);
            intent.putExtra("poster_path", poster_path);
            startActivity(intent);
            movieModelList.clear();

        }
    });
        // btn1.setText((id));


        return convertView;
    }

    public void click(String id) {
        btn1.setText(id);
    }

}

0 个答案:

没有答案