在列表视图中的活性粘排 [英] sticky row in listview in activity

查看:105
本文介绍了在列表视图中的活性粘排的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只有一行在我的列表视图应该是粘。不节或第一个行内的活动,而不是字母在stickyheaders.I真的AP preciate任何帮助WRT列表视图粘fragment.How做呢?我真的AP preciate提前任何help.Thanks。 使用code这样的:

 类MyAsyncTask扩展
        AsyncTask的<字符串,整数,ArrayList的< HashMap的<字符串,字符串>>> {

    //哈希映射为的ListView
    ArrayList的< HashMap的<字符串,字符串>> UploadsList =新的ArrayList< HashMap的<字符串,字符串>>();

    @覆盖
    在preExecute保护无效(){
        //显示进度对话框发送HTTP请求之前
        pDialog =新ProgressDialog(本);
        pDialog.setMessage(请稍候...);
        pDialog.setIndeterminate(真正的);
        pDialog.setCancelable(假);
        pDialog.show(); }

    @覆盖
    受保护的ArrayList< HashMap的<字符串,字符串>> doInBackground(
            字符串... PARAMS){

        //创建JSON解析器实例
        JSONParser jParser =新JSONParser();

        //从URL获取JSON字符串
        JSONObject的JSON = jParser.getJSONFromUrl(URL);

        尝试 {
            //获取上传的数组
            上传= json.getJSONArray(TAG_UPLOADS);

            //遍历所有上传
            的for(int i = 0; I< uploads.length();我++){
                JSONObject的C = uploads.getJSONObject(我);

                //保存在变量中的每个JSON项目
                字符串ID = c.getString(TAG_ID);
                字符串名称= c.getString(TAG_NAME);
                字符串日期= c.getString(TAG_DATE);

                //创建新的HashMap
                HashMap的<字符串,字符串>图=新的HashMap<字符串,字符串>();

                //添加每个子节点HashMap中的key =>值
                map.put(tag_id,分别编号);
                map.put(TAG_NAME,姓名);
                map.put(TAG_DATE,日期);

                //添加HashList到ArrayList中
                UploadsList.add(图)
            }
        }赶上(JSONException E){
            e.printStackTrace();
        }

        返回UploadsList;
    }

    @覆盖
    保护无效onPostExecute(ArrayList中< HashMap的<字符串,字符串>>的结果){

        pDialog.dismiss();

        ListAdapter适配器=新SimpleAdapter(这一点,因此,
                R.layout.list_item,
                新的String [] {TAG_NAME,tag_id,分别TAG_DATE},新的INT [] {
                R.id.name,R.id.id,R.id.date});

        setListAdapter(适配器);
    }
}
 

解决方案

我写这篇code对JSON ......希望这将解决您的难题。而你这个样子......

 < RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        的xmlns:工具=htt​​p://schemas.android.com/tool​​s
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        工具:上下文=MainActivity。>

        <的TextView
            机器人:ID =@ + ID / headerRow
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentLeft =真
            机器人:layout_alignParentRight =真
            机器人:layout_alignParentTop =真
            机器人:文本=@字符串/参考hello world/>

        <的ListView
            机器人:ID =@ + ID / ListView1的
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentBottom =真
            机器人:layout_alignParentLeft =真
            机器人:layout_alignParentRight =真
            机器人:layout_below =@ + ID / headerRow>

        < / ListView控件>

    < / RelativeLayout的>

    公共类MainActivity延伸活动{

        私人的ArrayList<字符串>数据;
        私人TextView的stickRow;

        @覆盖
        保护无效的onCreate(包savedInstanceState){
            super.onCreate(savedInstanceState);
            的setContentView(R.layout.activity_main);
            stickRow =(TextView中)findViewById(R.id.headerRow);
            数据=新的ArrayList<字符串>();
            为(中间体AK = 1; AK小于20; AK ++){
                data.add(行+ AK);
            }

            ListView的LV =(ListView控件)findViewById(R.id.listView1);
            lv.setAdapter(新CustomAdapter(getApplicationContext(),R.layout.activity_main));

        }

        类CustomAdapter扩展ArrayAdapter<字符串> {

            公共CustomAdapter(上下文的背景下,INT资源){
                超(背景下,资源);
            }

            @覆盖
            公共查看getView(INT位置,查看convertView,ViewGroup中父){
                // TODO自动生成方法存根
                如果(位置== 0){
                    stickRow.setText(的getItem(位置));
                }
                TextView的电视=新的TextView(getApplicationContext());
                tv.setTextSize(20);
                tv.setText(的getItem(位置+ 1));
                返回电视;
            }

            @覆盖
            公众诠释getCount将(){
                // TODO自动生成方法存根
                返回data.size() -  1;
            }

            @覆盖
            公共字符串的getItem(INT位置){
                // TODO自动生成方法存根
                返回data.get(位置);
            }

        }
    }
 

Just one row in my listview should be sticky .Not sections or section with alphabets in stickyheaders.I really appreciate any help w.r.t listview sticky one row within activity and not fragment.How do I do that ? I really appreciate any help.Thanks in Advance. Using code like :

class MyAsyncTask extends
        AsyncTask<String, Integer, ArrayList<HashMap<String, String>>> {

    // Hashmap for ListView
    ArrayList<HashMap<String, String>> UploadsList = new ArrayList<HashMap<String, String>>();

    @Override
    protected void onPreExecute() {
        // Showing progress dialog before sending http request
        pDialog = new ProgressDialog(this);
        pDialog.setMessage("Please wait..");
        pDialog.setIndeterminate(true);
        pDialog.setCancelable(false);
        pDialog.show();        }

    @Override
    protected ArrayList<HashMap<String, String>> doInBackground(
            String... params) {

        // Creating JSON Parser instance
        JSONParser jParser = new JSONParser();

        // getting JSON string from URL
        JSONObject json = jParser.getJSONFromUrl(url);

        try {
            // Getting Array of Uploads
            uploads = json.getJSONArray(TAG_UPLOADS);

            // looping through All Uploads
            for (int i = 0; i < uploads.length(); i++) {
                JSONObject c = uploads.getJSONObject(i);

                // Storing each json item in variable
                String id = c.getString(TAG_ID);
                String name = c.getString(TAG_NAME);
                String date = c.getString(TAG_DATE);

                // creating new HashMap
                HashMap<String, String> map = new HashMap<String, String>();

                // adding each child node to HashMap key => value
                map.put(TAG_ID, id);
                map.put(TAG_NAME, name);
                map.put(TAG_DATE, date);

                // adding HashList to ArrayList
                UploadsList.add(map);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return UploadsList;
    }

    @Override
    protected void onPostExecute(ArrayList<HashMap<String, String>> result) {

        pDialog.dismiss();

        ListAdapter adapter = new SimpleAdapter(this, result,
                R.layout.list_item,
                new String[] { TAG_NAME, TAG_ID, TAG_DATE }, new int[] {
                R.id.name, R.id.id, R.id.date });

        setListAdapter(adapter);
    }
}

解决方案

I wrote this code for Json... Hope this will solve your puzzle.. And you like this...

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity" >

        <TextView
            android:id="@+id/headerRow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:text="@string/hello_world" />

        <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/headerRow" >

        </ListView>

    </RelativeLayout>

    public class MainActivity extends Activity {

        private ArrayList<String> data;
        private TextView stickRow;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            stickRow = (TextView) findViewById(R.id.headerRow);
            data = new ArrayList<String>();
            for (int ak = 1; ak < 20; ak++) {
                data.add("Row " + ak);
            }

            ListView lv = (ListView) findViewById(R.id.listView1);
            lv.setAdapter(new CustomAdapter(getApplicationContext(), R.layout.activity_main));

        }

        class CustomAdapter extends ArrayAdapter<String> {

            public CustomAdapter(Context context, int resource) {
                super(context, resource);
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                // TODO Auto-generated method stub
                if (position == 0) {
                    stickRow.setText(getItem(position));
                }
                TextView tv = new TextView(getApplicationContext());
                tv.setTextSize(20);
                tv.setText(getItem(position + 1));
                return tv;
            }

            @Override
            public int getCount() {
                // TODO Auto-generated method stub
                return data.size() - 1;
            }

            @Override
            public String getItem(int position) {
                // TODO Auto-generated method stub
                return data.get(position);
            }

        }
    }

这篇关于在列表视图中的活性粘排的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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