これが私のmy_lifts_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="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 LiftActivity extends FragmentActivity {
private static final String TAG = LiftActivity.class.getName();
private ArrayList<Lift> mLifts = new ArrayList<Lift>();
private LiftArrayAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_lift_list);
mAdapter = new LiftArrayAdapter(this, R.layout.ride_item_card, mLifts);
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
LiftListFragment list = new LiftListFragment();
ft.add(android.R.id.content, list);
list.setListAdapter(mAdapter);
MyLiftsResponderFragment responder = (MyLiftsResponderFragment) fm.findFragmentByTag("RESTResponder");
if (responder == null) {
responder = new MyLiftsResponderFragment();
ft.add(responder, "RESTResponder");
}
ft.commit();
}
public void bookRide(View v){
Intent intent = new Intent(this, LiftSearchActivity.class);
startActivity(intent);
}
public LiftArrayAdapter getArrayAdapter() {
return mAdapter;
}
}
私のliftlistfragment:
public class LiftListFragment extends ListFragment {
private static final String TAG = LiftListFragment.class.getName();
private static final int ACTIVITY_VIEW_LIFT = 0;
@Override
public void onListItemClick(ListView list, View v, int position, long id) {
Lift item = (Lift) getListAdapter().getItem(position);
Intent intent = new Intent(this.getActivity(), LiftDetailActivity.class);
intent.putExtra("lift", item.getId());
intent.putExtra("time", item.getTime());
intent.putExtra("price", item.getPrice());
startActivity(intent);
}
}
そして最後に、私のリフトリストアダプター:
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;
}
}
つまり、基本的に、アイテムのリスト(クリック可能)と、下部にあるクリックできないボタンがあります。
このボタンが機能しない理由がわかりません。キーボードを使えば選択できます。listfragmentとactivityfragmentの間のonclicklistenerの使用に関するフラグメントの問題である必要があると思います(したがって、おそらく私のボタンはアイテムとして機能します)。これを実装するためのより良い方法はありますか?