-1

I've a listView with 10 items on it and an activity which contains a textView. I want to start the activity on listView ItemClick but with different textView in it. I am able to start the activity via intent but stuck how to change the value in textView . Is there any way to do this?

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

                    switch (position){
                        case 0:
                            Intent myIntent = new Intent(ListActivity.this, Districts.class);
                            ListActivity.this.startActivity(myIntent);
//I want textView to display 'abc'

                        case 1:
                            Intent myIntent = new Intent(ListActivity.this, Districts.class);
                            ListActivity.this.startActivity(myIntent);
//I want textView to display 'xyz'

                    }
                }
            });
suman
  • 125
  • 9
  • you mean you want to show the clicked listView item in your next activity textView ? – Sudheesh R Nov 13 '17 at 11:37
  • 1
    Possible duplicate of [How do I pass data between Activities in Android application?](https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application) – Abdul Waheed Nov 13 '17 at 11:41

1 Answers1

2

Pass data to intent

Intent myIntent = new Intent(ListActivity.this, Districts.class);
myIntent.putExtra("key","value");
ListActivity.this.startActivity(myIntent);

and get it in next activity

Bundle extras = getIntent().getExtras();
if (extras != null) {
    String value = extras.getString("key");
    textView.setText(value);
}
Gaurav
  • 3,615
  • 2
  • 27
  • 50