誰でも教えてください。リストビューからどのように選択できますか? listviewの1つの項目の行には、ラジオボタンが続くテキストが含まれています。単一選択モードから選択項目を取得listview - android
コード: 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>
と活動:
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);
}
}
細かい作業コード..
を私の質問はどのように設定する
1)されているデフォルトの選択?
2)選択したアイテムを取得しますか?
get select item http://stackoverflow.com/questions/4834750/how-to-get-the-selected-item-from-listvie w –
質問1. 'listView.setSelection(int position)' –