Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay the selected value of listview in the textview
    primarykey
    data
    text
    <p>I have a listview and textview in Activty When I click a value in a listview, that selected item will display in a textivew. I have attached my sample code,please help me.</p> <p><img src="https://i.stack.imgur.com/B4Ctm.png" alt="enter image description here"></p> <pre><code>MainActivity.java public class MainActivity extends Activity { TextView txt_disp; ListView lv; String fruits[]={"Apple","Orange","Banana","Grapes","kiwi"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txt_disp=(TextView)findViewById(R.id.textView1); lv=(ListView)findViewById(R.id.listView1); ArrayList&lt;SamplePOJO&gt; searchResults = GetSearchResults(); CustomAdapter ea=new CustomAdapter(this, searchResults); lv.setAdapter(ea); // here i need to set the text(txt_display) } } CustomAdapter.java public View getView(final int position, View convertView, ViewGroup parent) { final ViewHolder holder; if (convertView == null) { convertView = mInflater.inflate(R.layout.row1, null); holder = new ViewHolder(); holder.fruit=(TextView) convertView.findViewById(R.id.txt_fruit); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.fruit.setText(ContactArrayList.get(position).getFruit()); holder.fruit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub String dis=holder.fruit.getText().toString(); System.out.println("Selected Text:"+dis); //Selected text value set into textview in MainActivity } }); return convertView; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload