3

私はこのようなアプリを持っています:

ここに画像の説明を入力

私はこのhttp://developer.android.com/guide/components/fragments.html (アクティビティへのイベントコールバックの作成)に従おうとしましたが、うまくいかないようです。つまり、詳細を表示するために各行を選択したいと思います。また、必要な行のボタン a、b、または c をクリックできるようにしたいと考えています。ボタンをその行に関連付ける方法がわかりません。

これは私のrowLayout.xmlです:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="0,1">

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left">

            <ImageView
                android:id="@+id/imageViewTypeClient"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                tools:ignore="ContentDescription" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"/>
        </LinearLayout>

        <LinearLayout 
            android:gravity="right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ImageButton
                android:id="@+id/imageButtonSync"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:src="@android:drawable/stat_notify_sync"/>

            <ImageButton
                android:id="@+id/imageButtonDelete"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:src="@android:drawable/ic_menu_delete"
                tools:ignore="ContentDescription" />

            <ImageButton
                android:id="@+id/imageButtonEdit"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:src="@android:drawable/ic_menu_edit" />

        </LinearLayout>
    </TableRow>

</TableLayout>

欲しいものを注文するためにこの方法を作りました。

これは私のListFragmentです:

public class AplicacionActivity extends FragmentActivity implements OnEmployeeSelectedListener {


public void onEmployeeSelected(int id) {
    Log.e("activity aplicacion", "entre");
    Bundle arguments = new Bundle();
    arguments.putLong("id", id);
    DataClientActivity fragment = new DataClientActivity();
    fragment.setArguments(arguments);
    getSupportFragmentManager().beginTransaction()
            .replace(android.R.id.tabcontent,fragment, AplicacionActivity.tagFragmentDataClient)
            .commit();
}
...

}

そして、これは私の ListFragment です:

public class ClientsActivity extends ListFragment {


OnEmployeeSelectedListener mEmployeeListener;

public interface OnEmployeeSelectedListener {
        public void onEmployeeSelected(int id);
}

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {
        mEmployeeListener = (OnEmployeeSelectedListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " you must implement OnEmployeeSelectedListener");
    }
}

@Override
public void onListItemClick(ListView l, View v, int position, long id) {

    int idEmployee = position;  
    // Send the event and Uri to the host activity
    mEmployeeListener.onEmployeeSelected(idEmployee);
}

これを実行しようとしましたが、リストの任意の行を押しても onListItemClick は呼び出されません。それにもかかわらず、プレスボタンに対して同様のことをしなければならないかどうかはわかりません。

誰かが私にチュートリアルを提供してくれたり、正しい方向に導いてくれたりしたら、本当に感謝しています。

4

2 に答える 2

0

ListView.setItemsCanFocus(boolean)はあなたが探しているものだと思います。

于 2013-05-11T06:01:37.227 に答える