为什么我无法显示列表视图已被单击?如何使其能够展示?

发布于 2024-12-17 16:02:04 字数 1816 浏览 0 评论 0原文

在我的应用程序中,我使用此代码来显示带有部分的列表视图。 但通过这种方式,我无法获得我要选择的 listItem。我的意思是,当我按下任何列表项时,我看不到颜色的变化。那么如何使这段代码成为可能:

    public static ProgressDialog  m_progressDialog; 
    public Map<String,?> createItem(String title, String caption) {   
        Map<String,String> item = new HashMap<String,String>();   
        item.put(ITEM_TITLE, title);   
       item.put(ITEM_CAPTION, caption);   
        return item;   
    }   

    @Override  
    public void onCreate(Bundle icicle) {   
        super.onCreate(icicle);  
        setContentView(R.layout.main);

        // create our list and custom adapter   
        SeparatedListAdapter adapter = new SeparatedListAdapter(this);   
        adapter.addSection("Local documents:", new ArrayAdapter<String>(this,   
            R.layout.list_item, new String[] { "WindowsONE Mobile PK", "WindowsorONE Moldings","Filet for a burger video" }));
        adapter.addSection("Non-local resources:", new ArrayAdapter<String>(this,   
                R.layout.list_item, new String[] { "Launch Photo slideshow link", "Dealer locator link" }));
        adapter.addSection("Send emails:", new ArrayAdapter<String>(this,   
                R.layout.list_item, new String[] { "Send Dealer Locator email", "Send Catalog email","Send install instrucation link" })); 
        //For extra Information in Listview    
        //adapter.addSection("Non-local resources:", new SimpleAdapter(this, security, R.layout.list_complex,   
        //new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.list_complex_title, R.id.list_complex_caption }));        
        ListView list = getListView();
        list.setAdapter(adapter);   
        list.setTextFilterEnabled(true);
        list.setOnItemClickListener(this); 
}

}

In my application, I am using this code to show the List View with Section.
But with this way I am not able to get that which listItem I am going to select. I mean I am not able to see the chang colour while I am going to press on any list item. So how to make it possible for this code:

    public static ProgressDialog  m_progressDialog; 
    public Map<String,?> createItem(String title, String caption) {   
        Map<String,String> item = new HashMap<String,String>();   
        item.put(ITEM_TITLE, title);   
       item.put(ITEM_CAPTION, caption);   
        return item;   
    }   

    @Override  
    public void onCreate(Bundle icicle) {   
        super.onCreate(icicle);  
        setContentView(R.layout.main);

        // create our list and custom adapter   
        SeparatedListAdapter adapter = new SeparatedListAdapter(this);   
        adapter.addSection("Local documents:", new ArrayAdapter<String>(this,   
            R.layout.list_item, new String[] { "WindowsONE Mobile PK", "WindowsorONE Moldings","Filet for a burger video" }));
        adapter.addSection("Non-local resources:", new ArrayAdapter<String>(this,   
                R.layout.list_item, new String[] { "Launch Photo slideshow link", "Dealer locator link" }));
        adapter.addSection("Send emails:", new ArrayAdapter<String>(this,   
                R.layout.list_item, new String[] { "Send Dealer Locator email", "Send Catalog email","Send install instrucation link" })); 
        //For extra Information in Listview    
        //adapter.addSection("Non-local resources:", new SimpleAdapter(this, security, R.layout.list_complex,   
        //new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.list_complex_title, R.id.list_complex_caption }));        
        ListView list = getListView();
        list.setAdapter(adapter);   
        list.setTextFilterEnabled(true);
        list.setOnItemClickListener(this); 
}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

溺深海 2024-12-24 16:02:04

您可以为列表视图定义一个触摸监听器,并且可以显示触摸,例如

 ListView.setOnTouchListener(List_onTouch);

添加一个名为 List_onTouch 的触摸监听器

    OnTouchListener List_onTouch=new OnTouchListener(){
@Override
public boolean onTouch(View arg0,MotionEvent arg1){
    int iAction=arg1.getAction();
    if(iAction==0){
        ls2.setBackgroundcolor(Color.white);
    }
    else{
 ls2.setBackgroundcolor(Color.orange);     
   }
    return false;
}
};

ls2 是您的 listViewObject,如果您单击列表,它会将您的颜色更改为橙​​色

You can define a touch Listener to your list view and you can show the touch like

 ListView.setOnTouchListener(List_onTouch);

add a touch listner named List_onTouch

    OnTouchListener List_onTouch=new OnTouchListener(){
@Override
public boolean onTouch(View arg0,MotionEvent arg1){
    int iAction=arg1.getAction();
    if(iAction==0){
        ls2.setBackgroundcolor(Color.white);
    }
    else{
 ls2.setBackgroundcolor(Color.orange);     
   }
    return false;
}
};

ls2 is your listViewObject and if you click the list it will change your colour to orange

养猫人 2024-12-24 16:02:04

试试这个

getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);

Try this

getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文