Android Can';t单击带有列表视图的底部按钮
以下是我的my_\u list.xml:Android Can';t单击带有列表视图的底部按钮,android,android-listview,android-fragments,Android,Android Listview,Android Fragments,以下是我的my_\u list.xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vert
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/white_linen">
<LinearLayout android:id="@+id/bottom_control_bar"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button android:id="@+id/bookButton" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/bookRide"
android:onClick="bookRide"/>
</LinearLayout>
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_above="@id/bottom_control_bar"
android:divider="#b5b5b5"
android:dividerHeight="3dp"
android:listSelector="@drawable/custom_list_selector"/>
<TextView
android:id="@+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="You have not joined any rides."/>
</RelativeLayout>
最后,我的电梯列表适配器:
public class LiftArrayAdapter extends ArrayAdapter<Lift> {
private final ArrayList<Lift> lifts;
public LiftArrayAdapter(Context context, int textViewResourceId, ArrayList<Lift> results) {
super(context, textViewResourceId, results);
this.lifts = results;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// assign the view we are converting to a local variable
View v = convertView;
// first check to see if the view is null. if so, we have to inflate it.
// to inflate it basically means to render, or show, the view.
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.ride_item_card, null);
}
Lift i = lifts.get(position);
if (i != null) {
ImageView imageView = (ImageView) v.findViewById(R.id.list_image);
TextView departureDate = (TextView) v.findViewById(R.id.departureDate);
TextView driverName = (TextView) v.findViewById(R.id.driverName);
TextView placesRemaining = (TextView) v.findViewById(R.id.placesRemaining);
TextView ridePrice = (TextView) v.findViewById(R.id.ridePrice);
imageView.setTag(i.getDriver().getImage());
ImageLoader image = new ImageLoader();
image.execute(imageView);
if (departureDate != null){
departureDate.setText(i.getFrom().getDescription() + " vers " + i.getTo().getDescription());
}
if (driverName != null){
driverName.setText(i.getTime());
}
if (placesRemaining != null){
placesRemaining.setText("Places remaining : " + Integer.toString(i.getCapacity() - i.getPassengers().size()));
}
if (ridePrice != null){
ridePrice.setText("$" + Float.toString(i.getPrice()));
}
}
// the view must be returned to our activity
return v;
}
}
公共类LiftArrayAdapter扩展了ArrayAdapter{
私人最终ArrayList电梯;
公共LiftArrayAdapter(上下文上下文、int textViewResourceId、ArrayList结果){
super(上下文、textViewResourceId、结果);
这就是结果;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
//将要转换的视图指定为局部变量
视图v=转换视图;
//首先检查视图是否为空。如果是,我们必须将其充气。
//充气基本上意味着渲染或显示视图。
如果(v==null){
LayoutInflater充气器=(LayoutInflater)getContext().getSystemService(Context.LAYOUT\u充气器\u SERVICE);
v=充气机充气(R.layout.ride_item_card,空);
}
提升i=提升。获取(位置);
如果(i!=null){
ImageView ImageView=(ImageView)v.findViewById(R.id.list\u图像);
TextView departureDate=(TextView)v.findViewById(R.id.departureDate);
TextView driverName=(TextView)v.findViewById(R.id.driverName);
TextView placesRemaining=(TextView)v.findViewById(R.id.placesRemaining);
TextView ridePrice=(TextView)v.findviewbyd(R.id.ridePrice);
setTag(i.getDriver().getImage());
ImageLoader image=新的ImageLoader();
image.execute(imageView);
如果(离开日期!=null){
departureDate.setText(i.getFrom().getDescription()+“vers”+i.getTo().getDescription());
}
if(driverName!=null){
setText(i.getTime());
}
if(placesRemaining!=null){
placesRemaining.setText(“剩余位置:+Integer.toString(i.getCapacity()-i.getPassengers().size()));
}
if(ridePrice!=null){
ridePrice.setText(“$”+Float.toString(i.getPrice());
}
}
//视图必须返回到我们的活动
返回v;
}
}
因此,基本上,我有我的项目列表(可以点击),我的按钮在底部是不可点击的
我不明白为什么我不能让这个按钮工作。如果我使用键盘,我可以选择它。我假设它一定是某个片段在我的listfragment和我的activityfragment之间使用onclicklistener(因此,我的按钮可能充当一个项目)。有更好的方法来实现这一点吗?您为您的活动设置了布局文件,但随后将您的
LiftListFragment
片段直接添加到fragmentactivity
的内容Framelayout
(其id为android.R.id.content
),这将覆盖之前设置的整个布局。您确定不希望将LiftListFragment
添加到my\u lifts\u list.xml
布局文件中,如下所示:
<RelativeLayout>
// the button part
<FrameLayout android:id="@+id/liftfrag_wrapper" android:layout_above="@id/the_button" // other attributes/>
</RelativeLayout>
public class LiftArrayAdapter extends ArrayAdapter<Lift> {
private final ArrayList<Lift> lifts;
public LiftArrayAdapter(Context context, int textViewResourceId, ArrayList<Lift> results) {
super(context, textViewResourceId, results);
this.lifts = results;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// assign the view we are converting to a local variable
View v = convertView;
// first check to see if the view is null. if so, we have to inflate it.
// to inflate it basically means to render, or show, the view.
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.ride_item_card, null);
}
Lift i = lifts.get(position);
if (i != null) {
ImageView imageView = (ImageView) v.findViewById(R.id.list_image);
TextView departureDate = (TextView) v.findViewById(R.id.departureDate);
TextView driverName = (TextView) v.findViewById(R.id.driverName);
TextView placesRemaining = (TextView) v.findViewById(R.id.placesRemaining);
TextView ridePrice = (TextView) v.findViewById(R.id.ridePrice);
imageView.setTag(i.getDriver().getImage());
ImageLoader image = new ImageLoader();
image.execute(imageView);
if (departureDate != null){
departureDate.setText(i.getFrom().getDescription() + " vers " + i.getTo().getDescription());
}
if (driverName != null){
driverName.setText(i.getTime());
}
if (placesRemaining != null){
placesRemaining.setText("Places remaining : " + Integer.toString(i.getCapacity() - i.getPassengers().size()));
}
if (ridePrice != null){
ridePrice.setText("$" + Float.toString(i.getPrice()));
}
}
// the view must be returned to our activity
return v;
}
}
<RelativeLayout>
// the button part
<FrameLayout android:id="@+id/liftfrag_wrapper" android:layout_above="@id/the_button" // other attributes/>
</RelativeLayout>
ft.add(R.id.liftfrag_wrapper, list);