我是新手,我想在点击列表视图中询问我想在特定项目上选择(勾选)标记,我知道如何在点击项目上获得位置。这是我的代码在下面
public class MainActivity extends Activity {
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get ListView object from xml
listView = (ListView) findViewById(R.id.list);
// Defined Array values to show in ListView
String[] values = new String[]{"FirstName",
"FullName",
"Simple List View In Android"};
ArrayAdapter < String > adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);
listView.setClickable(true);
// Assign adapter to ListView
listView.setAdapter(adapter);
// ListView Item Click Listener
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// ListView Clicked item index
int itemPosition = position;
// ListView Clicked item value
String itemValue = (String) listView.getItemAtPosition(position);
// Show Alert
Toast.makeText(getApplicationContext(),
"Position :" + itemPosition + " ListItem : " + itemValue, Toast.LENGTH_LONG)
.show();
listView.getAdapter().getView(position, null, null).performClick();
}
});
}
}
谢谢......请
答案 0 :(得分:0)
检查this示例项目。这可能有所帮助。
答案 1 :(得分:0)
如果您需要多个选择,请使用此选项
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
如果您需要简要说明,请访问
http://theopentutorials.com/tutorials/android/listview/android-multiple-selection-listview/