android点击列表项目我想选择2项(刻度线)

时间:2022-06-01 23:44:48

I a newbie,i would like to ask on click list view i want to select (tick) mark on particular item,i know how to get position on click item.Here is my code below

我是新手,我想在点击列表视图上询问我想在特定项目上选择(勾选)标记,我知道如何获得点击项目的位置。这是我的代码如下

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();
            }

        });


        }

    }

Thank you..Please

2 个解决方案

#1


0  

Check this sample project. It may help.

检查此示例项目。它可能有所帮助。

#2


0  

Use this if you need multiple selections

如果您需要多个选择,请使用此选项

listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

If you need a brief description visit

如果您需要简要说明,请访问

http://theopentutorials.com/tutorials/android/listview/android-multiple-selection-listview/

#1


0  

Check this sample project. It may help.

检查此示例项目。它可能有所帮助。

#2


0  

Use this if you need multiple selections

如果您需要多个选择,请使用此选项

listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

If you need a brief description visit

如果您需要简要说明,请访问

http://theopentutorials.com/tutorials/android/listview/android-multiple-selection-listview/