package app.test;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class Test extends ListActivity {
String[] presidents;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView lstView = getListView();
// lstView.setChoiceMode(0); //CHOICE_MODE_NONE
// lstView.setChoiceMode(1); //CHOICE_MODE_SINGLE
lstView.setChoiceMode(2); // CHOICE_MODE_MULTIPLE
lstView.setTextFilterEnabled(true);
presidents = getResources().getStringArray(R.array.presidents_array);
setListAdapter(new ArrayAdapter(this,
android.R.layout.simple_list_item_checked, presidents));
}
public void onListItemClick(ListView parent, View v, int position, long id) {
parent.setItemChecked(position, parent.isItemChecked(position));
Toast.makeText(this, "You have selected " + presidents[position],
Toast.LENGTH_SHORT).show();
}
};
//main.xml
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
//strings.xml
Hello World, MainActivity!
BasicViews5
- Dwight D. Eisenhower
- John F. Kennedy
- Lyndon B. Johnson
- Richard Nixon
- Gerald Ford
- Jimmy Carter
- Ronald Reagan
- George H. W. Bush
- Bill Clinton
- George W. Bush
- Barack Obama