0

カスタムListViewを表示してからエントリを選択するためのDialogFragmentを作成しましたが、これは正常に機能しています。タイトルバーを削除できないことを除いて。setStyle(....) でタイトルを削除できますが、白いフィールドが残ります。http://developer.android.com/guide/topics/ui/dialogs.htmlを読み、AlertDialog を使用することが解決策になるという結論に達しました。クラスを変換して実際に動作させましたが、OnItemClickListener からイベントが発生しません...

動作中の DialogFragment は次のとおりです。

package com.SverkerSbrg.Spendo.Transaction.InsertTransaction.CategoryPicker;

import com.SverkerSbrg.Spendo.R;
import com.SverkerSbrg.Spendo.Category.CategoryList.CategoryList;
import com.SverkerSbrg.Spendo.Category.CategoryList.CategoryListChild;
import com.SverkerSbrg.Spendo.Category.Datastructure.Category;
import com.SverkerSbrg.Spendo.general.interfaces.CategoryReceiver;

import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class CategoryPickerFragment extends DialogFragment implements OnItemClickListener{
private CategoryReceiver receiver;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.category_picker_fragment, container);
    CategoryList categoryList = (CategoryList) view.findViewById(R.id.clCategories);
    categoryList.setOnItemClickListener(this);


    this.getDialog().setTitle(this.getActivity().getResources().getString(R.string.CategoryPicker_DialogHeader));

    return view;
}
public void setCategoryReceiver(CategoryReceiver receiver){
    this.receiver = receiver;
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Category category = ((CategoryListChild)view).getCategory();
    receiver.setCategory(category);
    this.dismiss();
}

}

そして、ここに AlertDialog があります:

package com.SverkerSbrg.Spendo.Tester;

import com.SverkerSbrg.Spendo.R;
import com.SverkerSbrg.Spendo.Category.CategoryList.CategoryList;
import com.SverkerSbrg.Spendo.Category.CategoryList.CategoryListChild;
import com.SverkerSbrg.Spendo.Category.Datastructure.Category;
import com.SverkerSbrg.Spendo.general.interfaces.CategoryReceiver;

import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class AlertDialogTest extends DialogFragment implements OnItemClickListener{
private CategoryReceiver receiver;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater();

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    View view = inflater.inflate(R.layout.category_picker_fragment, null);

    builder.setView(inflater.inflate(R.layout.category_picker_fragment, null));
    AlertDialog ad = builder.create();

    CategoryList categoryList = (CategoryList) view.findViewById(R.id.clCategories);
    categoryList.setOnItemClickListener(this);

    return ad;
}


public void setCategoryReceiver(CategoryReceiver receiver){
    this.receiver = receiver;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    System.out.println("adfafefawefaewfae");
    Category category = ((CategoryListChild)view).getCategory();
    receiver.setCategory(category);
    this.dismiss();
}
}

そして最後に、私がそれらを呼び出す方法は次のとおりです。

//      FragmentActivity a = (FragmentActivity) this.getContext();
//      AlertDialogTest adt = new AlertDialogTest();
//      adt.show(a.getSupportFragmentManager(), "CategoryPicker");
//      adt.setCategoryReceiver(this);

    CategoryPickerFragment cpfFragment = new CategoryPickerFragment();
    FragmentActivity a = (FragmentActivity) this.getContext();
    cpfFragment.show(a.getSupportFragmentManager(), "CategoryPicker");
    cpfFragment.setCategoryReceiver(this);

助けていただければ幸いです:)

4

1 に答える 1