Android如何从列表视图中获取textview字符串值

时间:2015-08-30 09:17:07

标签: android

我想要列表中的textview值,但它总是给出不是来自所选位置的最后一个值

public class myListAdapter extends ArrayAdapter<MyOrderData> implements OnClickListener  {

    public myListAdapter() {

        super(context, R.layout.myorder_list_row, myorderlist);

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View itemView = convertView;
        if (itemView == null) {
            LayoutInflater inflater = (LayoutInflater) getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            itemView = inflater.inflate(R.layout.myorder_list_row, null);
        }

        // /////
        MyOrderData currentdata = myorderlist.get(position);

        // TextView tvordernu, tvpackage, tvtotalgarment, tvorderdate,
        // tvpickupdate, tvpickuptime, tvstatus;

        txt_ticketno = (TextView) itemView.findViewById(R.id.tv_ticket_number);
        txt_raise_date = (TextView) itemView.findViewById(R.id.tv_raise_date);
        txt_service = (TextView) itemView.findViewById(R.id.tv_service);
        txt_time = (TextView) itemView.findViewById(R.id.tv_time);
        txt_status = (TextView) itemView.findViewById(R.id.tv_status);
        txt_view = (TextView) itemView.findViewById(R.id.tv_view);




        txt_ticketno.setText("" + currentdata.get_ticketnum());
        txt_raise_date.setText("" + currentdata.get_deliverdate());
        txt_service.setText("" + currentdata.get_service());
        txt_time.setText("" + currentdata.get_date());
        txt_status.setText("" + currentdata.get_status());




        txt_ticketno.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {


                Intent refresh = new Intent(context, Activity_ticket_details.class);



                refresh.putExtra("fname",""+txt_ticketno.getText().toString());



                context.startActivity(refresh);

            }
        });


        return itemView;



    }

我需要文字值

2 个答案:

答案 0 :(得分:1)

您不应该在“活动”之外调用点击侦听器。你想要做的是在你的活动中实现一个OnItemClickListener;您将获得(在其他参数中)所单击视图的位置,并且可以从适配器中检索相应的MyOrderData对象,您可以从中获取所需的字符串。

dm_attr_0001  r_object_type     i_folder_id
------------  ----------------  ----------------
         271  obj_type_A        0b00000080000001
         100  obj_type_B        0b00000080000001
          95  obj_type_B        0b00000080000002
(3 rows affected)

答案 1 :(得分:0)

我只是犯了一个错误而不是textview我可以在代码下面使用

refresh.putExtra(&#34; FNAME&#34;&#34;&#34;。+ currentdata.get_ticketnum()的toString());