如何更改项目的android的列表中查看选定的位置 [英] How can I change the position of Item selected in list View in android

查看:209
本文介绍了如何更改项目的android的列表中查看选定的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在在我所到所选项目的列表视图中的位置变为第一位置,并设置其它项目之一位置低于当前我怎样才能做到这一点的应用程序。
任何机构可以建议我一些教程或任何建议。

I am making an application in which I have to change the position of the selected item in list view to first position and set other items one position less than current How can i do this. Can any body suggest me some tutorial or any suggestion.

推荐答案

使用适配器,和ArrayList 单击从该位置删除该项目。出它第0位置,并使用 notifyDataSetChanged 来reaarange列表视图

Use Adapter, and arraylist on item click remove the item from that position. out it at the 0th position and use notifyDataSetChanged to reaarange the listview

import java.util.ArrayList;

import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Main_Screen extends ListActivity implements OnItemClickListener{
    ArrayAdapter arrayAdapter = null;
    /** Called when the activity is first created. */
    Context context = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        penList.add("MONT Blanc");
        penList.add("Gucci");
        System.out.println("...1...");
        arrayAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, penList);
        arrayAdapter.add("last by adapter");


        setListAdapter(arrayAdapter);
        penList.add("Last By list");
        arrayAdapter.add("last by adapter2");

        getListView().setTextFilterEnabled(true);
        ListView lv = getListView();
        this.registerForContextMenu(lv);

        lv.setOnItemClickListener(this);


    }



    static ArrayList<String> penList   = new ArrayList<String>();
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        // TODO Auto-generated method stub
        String str = penList.get(arg2);
        penList.remove(arg2);
        penList.add(0, str);
        arrayAdapter.notifyDataSetChanged();
    }




}

这篇关于如何更改项目的android的列表中查看选定的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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