Basically what I am doing is giving a user a list of terms via listview. The terms are defined as strings in strings.xml:
<item name="Bahrain testing">Bahrain</item>
<item name="Bangladesh testing">Bangladesh</item>
<item name="Barbados testing">Barbados</item>
<item name="Belarus testing">Belarus</item>
<item name="Belgium testing">Belgium</item>
<item name="Belize testing">Belize</item>
<item name="Benin testing">Benin</item>
I deal with the ListView in myActivity.java:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.seoguide);
String[] countries = getResources().getStringArray(R.array.seoterm_array);
setListAdapter(new ArrayAdapter<String>(this, R.layout.seoguide, countries));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
This is where I kind of come to the end of my rope, I’ve tried defining it via item name by getting attributes, but that doesnt seem to work.
I suspected an issue could come from not having clickable defined in seoguide.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="22sp" >
</TextView>
But I have not seen clickable defined in the XML of other tutorials.
What I would like to happen, is when a user selects, say, Bahrain, that Toast would pop up a message saying something like “Baharain is a small island state near the western shores of the Persian Gulf.”
Thanks in advance for the help!
EDIT
changed myview.xml to seoguide.xml – which reflects the same information
1 Answer