您好我正在使用此代码在另一个列表视图中创建列表视图
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) {
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;
}
}
}
}
但我发现内部列表视图不是滚动,任何人都可以帮助我吗? 谢谢; http://i.stack.imgur.com/uKQlZ.png 和图像在这里
答案 0 :(得分:2)
您应该使用ExpandableListView
。
内部列表不滚动,因为ListView
实现了自己的滚动条并拦截了所有滚动手势。