开发者

InnerList View is not Scrolling

Hi I am creating a List View in another List View using this code

package com.ltest;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class LTestActivity extends Activity {
/** Called when the activity is first created. */
String[] str1 = {"one1","two1","three1","four1","five1"};
String[] str2 = {"one2","two2","three2","four2","five2"};
String[] str3 = {"one3","two3","three3","four3","five3"};
String[] str4 = {"one4","two4","three4","four4","five4"};
String[] str5 = {"one5","two5","three5","four5","five5"};
String[][]str = {str1,str2,str3,str4,str5};
String[] ttl = {"A","B","C","D","E"};
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ListView lv = (ListView)findViewById(R.id.list_main);
    lv.setAdapter(new EfficientAdapter(this,str,ttl));
}



public class EfficientAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private String[][] str;
    private String[] ttl;
    Context context;
    public EfficientAdapter(Context context,String[][] str, String[] ttl) {
        mInflater = LayoutInflater.from(context);
        this.str = str; 
        this.context = context;
        this.ttl = ttl;
    }

    public int getCount() {
        return str.length;
    }

    public Object getItem(int position) {开发者_StackOverflow中文版
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.custom_list,null);
            TextView tv_ttl = (TextView)convertView.findViewById(R.id.text_ttl);
            ListView InnerList = (ListView) convertView.findViewById(R.id.list);
            InnerList.setAdapter(new InnerEfficientAdapter(context, str[position])); 
            tv_ttl.setText(ttl[position]);
        } 
        return convertView;
    }

    public class InnerEfficientAdapter extends BaseAdapter {
        private LayoutInflater mInflater;
        private String[] str;

        public InnerEfficientAdapter(Context context,String[] str) {
            mInflater = LayoutInflater.from(context);
            this.str = str; 
        }

        public int getCount() {
            return str.length;
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.custom_list_second,null);
                TextView tv = (TextView) convertView.findViewById(R.id.text);
                tv.setText(str[position]); 
            } 
            return convertView;
        }
      }
     }

 }

but I found that the inner List View is not Scrolling, any one can help me ? thanks;

InnerList View is not Scrolling

http://i.stack.imgur.com/uKQlZ.png and Image is here


You should use ExpandableListView.

Inner lists aren't scrolling because ListView implements its own scroller and intercept all scroll gestures.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜