Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to add textview to listview in android

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends Activity {
    TextView tv;
    ListView lv;
      String s="";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         tv=(TextView) findViewById(R.id.textView1);
         lv=(ListView) findViewById(R.id.listView1);

        String value[]={"asda","Ansar","Nisam"};
        ArrayAdapter<String>adapter=new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1,android.R.id.text1,value);
        lv.setAdapter(adapter);
//list item click
            lv.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                        long arg3) {
                     s=s+("
")+((String) lv.getItemAtPosition(arg2));
                    tv.setText(s);
                }

            });

    }
Comment

PREVIOUS NEXT
Code Example
Java :: java how to fill an array 
Java :: java check if property exists in class 
Java :: primefaces download file 
Java :: create a hashmap 
Java :: android access main toolbar in fragment 
Java :: java how to print out a string in uppercase 
Java :: sound file java 
Java :: get spring application context 
Java :: java super keyword 
Java :: Loop in singly linked list 
Java :: spring 5 jdbctemplate query for a single value 
Java :: android java show hide keyboard: 
Java :: how to concatenate two strings in java 
Java :: isEmpty java code 
Java :: on item click listener for recyclerview adapter 
Java :: main method in java 
Java :: what is static setter and getter examples in java 
Java :: How to return the elements of a matrix in spiral order, in Java? 
Java :: java loops 
Java :: interface extending interface in java 
Java :: android studio reg get float from numeric string 
Java :: How to summon an item in bukkit 
Java :: pass a list of string as PathVariable to api spring boot 
Java :: java sort arraylist of floats 
Java :: could not find java in a java_home at /opt/java/openjdk/bin/java docker sonarqube 
Java :: java convert url/image to drawable 
Java :: how to create a subclass in java 
Java :: calling java static method in kotlin 
Java :: export java path in ubuntu 
Java :: remove selected text from string value android java 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =