Loading ...

Bind data from a listview from a String array | CodeAsp.Net

Yukti Arora likes this.

Comments (1)

Ramesh Kumar said:
wow exactly what i need. but i want open the 'countires_IDs' in another activity. how to open as another activity. please help me. thank you.
Ravi Rawal said:
Hi, Ramesh Thank you for your feedback. I have updated the code i.e. : Add a new XML file and name it as: country_details.xml Code for file: Now Create a class and name it as: CountryNameDisplay Code for file: package com.listview_string.codeasp.listview_string; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; public class CountryNameDisplay extends AppCompatActivity{ TextView countryNameDisplay; String country_name; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle extras = getIntent().getExtras(); country_name = extras.getString("country_name"); setContentView(R.layout.country_details); countryNameDisplay = (TextView) findViewById(R.id.country_name_selected); countryNameDisplay.setText(country_name); } } Now in class: MainActivity update your method: "onItemClick" to: @Override public void onItemClick(AdapterView adapter, View view, int position, long id) { Toast.makeText(getApplicationContext(), countires_IDs[position], Toast.LENGTH_LONG).show(); Intent intent = new Intent(this, CountryNameDisplay.class); intent.putExtra("country_name", countires_IDs[position]); startActivity(intent); } Also don't forget to update your manifest file add your new class, to do that, add code: This will do the job. Happy to help.

Top posts

Most Recent Blogs

Quick Vote

What kind of email newsletter would you prefer to receive from CodeAsp.Net?