How to get the value from the listview

扶醉桌前 提交于 2019-12-11 05:30:09

问题


How to get the value from the ListView ,

i.e when an list item is clicked it sends the data from the ListViewand set the value of ListView in an EditText.


回答1:


Try this:

listview.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) {
            Toast.makeText(<Your Class Name>.this,
                "posisiton: "+position+" "+"Id: "+id, Toast.LENGTH_SHORT).show();
        }
});



回答2:


Something like this:

list.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {  
   public void onItemSelected(AdapterView parentView, View childView, int position, long id) {  
            String str = ((TextView)childView).getText().toString();
            (EditText)findViewById(R.id.EditText01).setText(str);
        }

      });  

This thread and this thread should help




回答3:


View curr = adapter.getView(getSelectedItemPosition(),null,null);
TextView c = (TextView)curr.findViewById(R.id.detail);


来源:https://stackoverflow.com/questions/4966055/how-to-get-the-value-from-the-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!