how to add textview to listview in android

Solutions on MaxInterview for how to add textview to listview in android by the best coders in the world

showing results for - "how to add textview to listview in android"
Ava
01 Sep 2019
1import android.app.Activity;
2import android.os.Bundle;
3import android.view.Menu;
4import android.view.View;
5import android.widget.AdapterView;
6import android.widget.AdapterView.OnItemClickListener;
7import android.widget.ArrayAdapter;
8import android.widget.ListView;
9import android.widget.TextView;
10
11public class MainActivity extends Activity {
12    TextView tv;
13    ListView lv;
14      String s="";
15    @Override
16    protected void onCreate(Bundle savedInstanceState) {
17        super.onCreate(savedInstanceState);
18        setContentView(R.layout.activity_main);
19         tv=(TextView) findViewById(R.id.textView1);
20         lv=(ListView) findViewById(R.id.listView1);
21
22        String value[]={"asda","Ansar","Nisam"};
23        ArrayAdapter<String>adapter=new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1,android.R.id.text1,value);
24        lv.setAdapter(adapter);
25//list item click
26            lv.setOnItemClickListener(new OnItemClickListener() {
27
28                @Override
29                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
30                        long arg3) {
31                     s=s+("\n")+((String) lv.getItemAtPosition(arg2));
32                    tv.setText(s);
33                }
34
35            });
36
37    }