在列表视图中检索和TextView的值

时间:2013-10-26 15:42:51

标签: android android-listview textview android-adapter

我用适配器获取了这个ListView:

date_status_pending_listview.setAdapter(arrayAdapter_pending);

适配器的定义如下:

arrayAdapter_pending = new SimpleAdapter(context, dates_pending, R.layout.date_status_list_item, columns, to){

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


                            if (convertView == null) {
                                LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                                convertView = vi.inflate(R.layout.date_status_list_item, null);
                            }

                            TextView tt = (TextView) convertView.findViewById(R.id.text_uid);
                            tt.setText(dates_pending.get(position).get("id_request"));
....

                            return convertView;
                        }
                    };

我想要的是在单击某个项目时获取uid_request的值,然后转到另一个活动。

// A C T I O N    B U T T O N S (I T E M   S E L E C T E D - P E N D I N G) 
    date_status_pending_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent,android.view.View v, int position, long id) {

        }
    });

我该怎么做?

2 个答案:

答案 0 :(得分:0)

在填写textViews的方法中做同样的事情

date_status_pending_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent,android.view.View v, int position, long id) {

          dates_pending.get(position).get("id_request");

         //Go To Another Activity

        }
    });

答案 1 :(得分:0)

      date_status_pending_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
       public void onItemClick(AdapterView<?> parent,android.view.View v, int position, long id) {
        String id = dates_pending.get(position).get("id_request");
        Intent i=new Intent(this,NextScreen.class);
        i.putExtra("ID",id);
        startActivity(i);

      }
  });

在下一个屏幕上:

  Bundle extras=getIntent().getExtras();
  String id=extras.getString("ID");
  System.out.println("SELECTED ID IS"+id);