开发者

Are the ListView equipped of some system to enable clicked item to stay selected?

As the title say.. Are the ListView equipped of some system to enable clicked item to stay 开发者_运维知识库selected ?

Thanks.


Besides, focus there is no such thing. You can improvise it by setting color to the item.


Unfortunately not.

Here is an answer previously provided: Highlight ListView selected row

Because of the way the Android Framework is designed with Touch Mode, there is no way to do so without creating a custom ListView and programatically setting the background to a different color. You can keep track of your "last selected view" either through an id, a position, or a reference to the view itself.

Another option is to do this in a custom adapter's bind view, although this is more of a hassle because all your views have to be rebuilt in order for it to work properly.

I have read somewhere that they are to fix this issue in the Honeycomb though.


Sorry guys but i found a way to do so and it work fine. It was exactly what i was looking for. To help others i will post an exemple.

  1. First, you have to implement the mode in the layout with android:choiceMode="singleChoice".

  2. You need to specify a multi-choice list in the adapter.

ArrayAdapter adapter = new ArrayAdapter(monContext, android.R.layout.simple_list_item_single_choice, maListePrenoms);

3.Then in the code you can get the value of the selected item...

btnAfficherNom.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                Toast.makeText(monContext, lstPersonnes.getItemAtPosition(lstPersonnes.getCheckedItemPosition()).toString(), Toast.LENGTH_SHORT).show();
            }
        });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜