anyone please tell me, how can i get selected from listview.? my single item row from listview contains a text followed by a radiobutton.
Code: XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
/>
</LinearLayout>
and activity:
public class MainActivity extends Activity {
String[] countries = new String[] {
"India",
"Pakistan",
"Sri Lanka",
"China",
"Bangladesh",
"Nepal",
"Afghanistan",
"North Korea",
"South Korea",
"Japan"
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Getting object reference to listview of main.xml
ListView listView = (ListView) findViewById(R.id.listview);
// Instantiating array adapter to populate the listView
// The layout android.R.layout.simple_list_item_single_choice creates radio button for each listview item
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice,countries);
listView.setAdapter(adapter);
}
}
the code working fine..
but my questions are
1) how to set default selection ?
2) get selected item ?