【发布时间】:2017-01-06 12:44:42
【问题描述】:
public class MyAdapter extends BaseAdapter implements ListAdapter {
private List<String> events = new ArrayList<String>();
private Context context;
public MyAdapter(List<String> events, Context context) {
this.events = events;
this.context = context;
String a = String.valueOf(events.size());
Toast.makeText(context,a,Toast.LENGTH_LONG).show();
}
@Override
public int getCount() {
return events.size();
}
@Override
public Object getItem(int position) {
return events.get(position);
}
@Override
public long getItemId(int position) {
//return events.get(position).getId();
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.list_item_layout, null);
}
TextView listtv = (TextView) view.findViewById(R.id.label1);
listtv.setText(events.get(position));
Button delbutton = (Button) view.findViewById(R.id.del_button);
delbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(context,"You didn' code this feature yet",Toast.LENGTH_LONG).show();
}
});
return view;
}
}
我正在创建一个 MyAdapter 对象并通过传递 List 和 Activity.this 来调用它 当我尝试为传递的列表的大小敬酒时,我得到了正确的大小 但是只有列表的第一项显示在屏幕上
我的 Xml`
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#00000000">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/label1"
android:padding="10dp"
android:textSize="15dp"
android:textStyle="bold"
android:gravity="center"
>
</TextView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/del_button"
android:background="#00000000"
android:drawableTop="@drawable/ic_close_black_24dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:paddingTop="10dp"
>
</Button>
</RelativeLayout>`
我的主要布局文件是
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_cal_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.test123.CalView"
tools:showIn="@layout/activity_cal_view">
<ListView
android:id="@+id/list_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</ListView>
</RelativeLayout>
【问题讨论】:
-
xml 请?????????/
-
我们需要您的 AXML 文件和您的布局。
-
@jeremy 你在 ScrollView 中使用 Listview 吗?
-
@UsmanRana 不,列表视图在相对布局内