得到""来自ListView setOnItemClickListener视图的dialogFragment

时间:2014-05-30 18:06:09

标签: android listview android-dialogfragment

这是一个!你有......

public class SomePopup extends DialogFragment implements View.OnClickListener

它自己创建一个ListView

public ListView happyListView;
public HappyAdapter ourAdaptor;

然后在里面......

public View onCreateView(LayoutInflater inflater,
    ViewGroup container,
    Bundle savedInstanceState)

..像往常一样设置列表。在这种情况下,用户可以点击"任何行",并执行此操作...这也在onCreateView ...

happyListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
    {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id)
      {
      ParseUser chosen = (ParseUser) happyListView.getItemAtPosition(position);
      Utils.Log("YOU CLICKED ON .......... " + .. chosen);

      // actually close this entire DialogFragment
      SOMETHING.dismiss();

      }
    });

注意SOMETHING。你是怎么做到的?!

我通过回调创建DialogFragment的类并使用该实例.dismiss()DialogFragment来解决它。

但你如何得到这个&#34;这个&#34;你在happyListView.setOnItemClickListener里面的DialogFragment?

干杯

1 个答案:

答案 0 :(得分:3)

您可以在课程名称this之后调用该课程并将SomePopup(作为SomePopup.this的引用)放入..只有在happyListView.setOnItemClickListener为{}时才会有效在dialogfragment中..因为它是一个匿名类..

示例:

happyListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
  {
  ParseUser chosen = (ParseUser) happyListView.getItemAtPosition(position);
  Utils.Log("YOU CLICKED ON .......... " + .. chosen);

  // actually close this entire DialogFragment
  SomePopup.this.dismiss();

  }
});