I've got the following main.xml:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ListView
android:id="@+id/listview"
android:layout_width="315px"
android:layout_height="379px"
android:layout_x="2px"
android:layout_y="50px"
>
</ListView>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select device:"
android:textSize="17sp"
android:layout_x="-2px"
android:layout_y="1px"
>
</TextView>
<Button
android:id="@+id/refresh"
android:layout_width="109px"
android:layout_height="wrap_content"
android:text="Refresh"
android:layout_x="209px"
android:layout_y="7px"
>
</Button>
</AbsoluteLayout>
The main class does nothing but drawing the layout.
I've got the following class and layout for the listitems:
<?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="16sp" >
</TextView>
package com.android.bluetoothp2p;
import android.app.ListActivity;
import android.os.Bundle;
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;
import android.widget.Toast;
public class BTListView extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, 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();
}
});
}
Countries is just an array with a list of countries, some dummy values.
Now, how do I make the list items of the BTListView class go in the ListView (with @+id/listview) of the main class?
EDIT: Now my list works, but it isn't clickable anymore. This is the code:
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(), "lolwat", Toast.LENGTH_SHORT).show();
}
});