0

ListView から選択した項目を取得しようとしましたが、リスナーから応答がありません

このコードからログに呼び出しがありません。

public void onItemSelected(AdapterView<?> spinnerReference,
        View rowReference, int arg2, long arg3) {

        chooseExercise = itemsList.getSelectedItem().toString();
        Log.i("choosed", chooseExercise);
}

私のアダプター:

public void setItemList(String muscle)
{

if (muscle.equals("All"))
    items = data.getAllExercies();
else
    items = data.getMuscleEx(muscle);

ArrayAdapter<CharSequence> exerciseAdapter;

if (items == null || items.length < 1)
    items = new String[] {};

exerciseAdapter = new ArrayAdapter<CharSequence>(this,
        android.R.layout.simple_spinner_item, items)
{

    @Override
    public View getView(int position, View convertView,
            ViewGroup parent) {

        String text = items[position];

        TextView listItem = new TextView(AddWorkOutPage.this);
        listItem.setBackground(getResources().getDrawable(R.drawable.shape_box));
        listItem.setTextSize(18);
        listItem.setText(text);
        listItem.setPadding(10, 20, 0, 20);;
        listItem.setTextColor(Color.BLACK);

        return listItem;
    }
};

// Specify the layout to use when the list of choices appears

// Apply the adapter to the spinner
searchItemField.setAdapter(exerciseAdapter);
itemsList.setAdapter(exerciseAdapter);

}

私のリストビューオブジェクトコード:

public void addExerciseDialog()
     {       
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Choose exercise");

            View prefView = View.inflate(this, R.layout.choose_from_list, null);    

            searchItemField = (AutoCompleteTextView) prefView.findViewById(R.id.searchItemField);
            itemsList = (ListView) prefView.findViewById(R.id.itemsList);

            searchItemField.setDropDownHeight(0);

            searchItemField.addTextChangedListener(this);

            setItemList(wantedMuscle);

            itemsList.setOnItemClickListener(this);

            builder.setPositiveButton("Choose selected", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) 
                {
                    Log.i("exercise choose", chooseExercise);
                    dialog.dismiss();
                }
            });

            builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) 
                {
                    dialog.dismiss();
                }
            });

            builder.setNeutralButton("filter", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) 
                {
                    createDialog();
                }
            });

            builder.setView(prefView);

            builder.show();
     }

私のダイアログXMLコード:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/White"
    android:descendantFocusability="beforeDescendants"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:src="@android:drawable/ic_menu_search" />

    <ListView
        android:id="@+id/itemsList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/searchItemField"
        android:descendantFocusability="beforeDescendants"
        android:layout_marginTop="5sp" >

    </ListView>

    <AutoCompleteTextView
        android:id="@+id/searchItemField"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"       
        android:layout_toLeftOf="@+id/imageView1"
        android:ems="10" >

        <requestFocus />
    </AutoCompleteTextView>

</RelativeLayout>
4

1 に答える 1