如何保持列表视图索引选定的,并强调? [英] How to remain the listView index selected and highlighted?

查看:162
本文介绍了如何保持列表视图索引选定的,并强调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我有落实的ListView 。 现在,我希望它设置成这样的:如果我选择在perticular指标作为选择,应该保留。答显示为的ListView 选择。 如果我选择另一个索引那么现在,当选择新的索引应该保持不变。

In My app i have implement the ListView. Now i want it to set as like that: If i select on perticular index it should be remain as selected. ans appear as selected on ListView. If i select another index then now that new index should be remain as selected.

编辑

意味着我要设置为选定的指数应继续作为选择,直到我选择另一所强调的。但不喜欢多选择。

Means I want to set as the selected index should remain as highlighted as selected till I select another. but not like multiple selected.

那么怎么办呢?

请帮我为这一点。 我已经实现了的ListView 像下面code:

Please help me for that. I have implemented the ListView as like below code:

phonemesListView = (ListView) findViewById(R.id.phonemsListView);
private String[] Phonemes_List = new String[]{"P","B","T","D","K","G","N","M","ING","TH v","TH vl","F","V","S","Z","SH","CH","J","L","R rf","R b"};

phonemesListView.setAdapter(new ArrayAdapter<String>(this,R.layout.phonemes_list_row, R.id.phonemes,Phonemes_List));
    @Override
    public void onItemClick(AdapterView<?> parent, View view,final int Position,long id) {
        phonemsText.setText(Phonemes_List[Position]);
        Toast.makeText(getApplicationContext(), "Phonems: "+Phonemes_List[Position], Toast.LENGTH_SHORT).show();
//      view.setBackgroundColor(Color.RED);
//      phonemesListView.setBackgroundColor(Color.BLUE);
        jumposition = Position;             
        int temp = 0;              
        if(jumpCount == -1){                 
            view.setBackgroundColor(Color.BLUE);                  
            jumpCount = jumposition;                 
            JumpView = view;                  
            temp = 1;             
        }              
        if(temp == 0) {                 
            if(jumpCount == jumposition) {                     
                view.setBackgroundColor(Color.BLUE);                     
                JumpView = view;                 
            }                 
            else{                     
                JumpView.setBackgroundColor(Color.TRANSPARENT);                     
                view.setBackgroundColor(Color.BLUE);                      
                jumpCount = jumposition;                     
                JumpView = view;                 
            }             
        }
    }

感谢。

推荐答案

您可以只保存从数据持有人所使用来填充您的ListView选择的位置。然后,您可以使用 setSelection(位置)的ListView设置所选位置属性,只要你想保持选中状态。

You can just save the selected position from the data holder that you are using to populate your ListView. Then, you can use setSelection(position) attribute of ListView to set the selected position remain selected whenever you want.

这篇关于如何保持列表视图索引选定的,并强调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆