user3749720 February 2016

how listView item add content in editText box?

How to add listView item content in editText box when user touch on liistView item

enter image description here

Answers


Damanpreet Singh February 2016

First of all you need to take EditText object

EditText et = (EditText)findViewById(R.id.edit_text);
ListView listview = (ListView)findViewById(R.id.listview);

Now you need to set onItemClickListener on listview.

listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
        String item = listView.getItemAtPosition(position);
        et.setText(item);             
    }
});

I am assuming your are using normal adapter with string as an item as you haven't shown any specific customadapter code.


John Joe February 2016

To make the list clickable, apply OnItemClickListener

In order to get the content, you need to define the position of the object, then use setText, and get the content based on the position.

 listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> listView, View view,
                                    int position, long id) {

            Object o = listview.getItemAtPosition(position);
            SearchResults fullObject = (SearchResults) o;
            String content = fullObject.getContent();
                Content.setText(content); // set content to your Content editText 

            }
        });


Nidhin Prathap February 2016

Step 1: Initalize the textView

EditText etSetText ;
etSetText = (EditText) findViewById(R.id.EDITTEXTID); 

Step 2: Handle OnClickListner of ListView Get Clicked Item Set Text to the Initialized TextView

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> listView, View view,
                                int position, long id) {

            String selectedText = listView.getItemAtPosition(position);
            etSetText.setText(selectedText)
        }
 });

Post Status

Asked in February 2016
Viewed 1,918 times
Voted 14
Answered 3 times

Search




Leave an answer