在我的应用程序中,我需要创建两个列表,每个列表都有不同的数据。我设计了UI,就像在LinearLayout中的TableLayout中一个接一个地添加两个列表视图。我已将数据存储在两个String数组中,并使用arrayadapter填充到listview.My listview包含textview和image.问题是
1.代码中没有显示错误,但列表以奇怪的方式填充。显示第1个列表项目,第2个,第3个,第4个列表项目未显示,第5个未显示第6个,从7日起罚款。当我向上滚动时,列表显示所有列表项。
2.每个列表应该有自己的滚动控件。就像我滚动列表“A”一样,它应该只滚动而不是列表“B”,反之亦然。我在这里附上了代码。提前谢谢。
mainscreen.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_LinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:id="@+id/request_Table"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@color/black"
android:orientation="vertical"
android:padding="20dp" >
<TableRow
android:id="@+id/request_Row1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/blue"
android:orientation="vertical" >
<TextView
android:id="@+id/request_TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="REQUESTS"
android:textColor="@color/white"
android:textStyle="bold" />
<ImageView
android:id="@+id/widget163"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</TableRow>
<TableRow
android:id="@+id/request_Row2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/gray"
android:orientation="horizontal" >
<ListView
android:id="@+id/request_ListView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:scrollbarAlwaysDrawVerticalTrack="true" />
</TableRow>
</TableLayout>
<TableLayout
android:id="@+id/offered_Table"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@color/black"
android:orientation="vertical"
android:padding="20dp" >
<TableRow
android:id="@+id/offered_Row1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/blue"
android:orientation="horizontal" >
<TextView
android:id="@+id/offered_TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="OFFERED"
android:textColor="@color/white"
android:textStyle="bold" />
</TableRow>
<TableRow
android:id="@+id/offered_Row2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ListView
android:id="@+id/offered_ListView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/gray"
android:padding="5dp"
android:scrollbars="vertical"
android:smoothScrollbar="true" />
</TableRow>
</TableLayout>
</LinearLayout>
mainscreen.java
public class MainMenu extends Activity {
RequestAdapter mRequestAdapter;
ListView mListView_req ;
public class RequestData {
int icon;
String list_text;
public RequestData( String mText) {
super();
//this.icon=image;
this.list_text=mText;
}
}
private RequestData[] getListItems(){
Resources mRes = getResources();
String[] sListItems= mRes.getStringArray(R.array.request_list);
int listsize = sListItems.length;
RequestData[] obj = new RequestData[listsize];
int size = obj.length;
for(int i=0; i<size; i++){
obj[i] = new RequestData(sListItems[i]);
}
return obj;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainmenu_screen);
mListView_req= (ListView)findViewById(R.id.request_ListView) ;
mRequestAdapter = new RequestAdapter(this,R.layout.listitem, getListItems());
mListView_req.setAdapter(mRequestAdapter);
}
class RequestAdapter extends ArrayAdapter{
private RequestData rList[]= null;
Context context;
public RequestAdapter(Context context, int textViewResourceId,
RequestData[] data) {
super(context, textViewResourceId, data);
// TODO Auto-generated constructor stub
this.rList= data;
}
@Override
public RequestData getItem(int position){
return rList[position];
}
@Override
public View getView(int pos, View convertView, ViewGroup parent) {
View row= convertView;
if (row== null){
row = getLayoyutinflater().inflate(R.layout.listitem,null);
}
else {
RequestData items = getItem(pos);
TextView text= (TextView) row.findViewById(R.id.List_Text);
if(text!= null){
text.setText(items.list_text);
}
}
return row;
}
listitem.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="150dp">
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:id="@+id/text"/>
<ImageView>
android:layout_width="40dp"
android:layout_height="wrap_content"
android:src="@drawable/arrow"
android:layout_marginRight="10dp"/>
</LinearLayout>