Android ListView上的setOnItemClickListener不工作

Android ListView上的setOnItemClickListener不工作,android,android-fragments,onitemclicklistener,Android,Android Fragments,Onitemclicklistener,我在片段视图中管理侦听器时遇到一些困难。当我按下列表中的项目时,什么也没发生。请检查我的代码,让我知道我是否做对了,或者我的代码有什么问题 public class People extends BaseFragment implements OnClickListener { static String name; ListView listview; TextView et; static public List<SuccessStoreyItem>

我在片段视图中管理
侦听器时遇到一些困难。当我按下列表中的项目时,什么也没发生。请检查我的代码,让我知道我是否做对了,或者我的代码有什么问题

public class People extends BaseFragment implements OnClickListener {
    static String name;
    ListView listview;
    TextView et;
    static public List<SuccessStoreyItem> success_list3 = new ArrayList<SuccessStoreyItem>();
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
        // TODO Auto-generated method stub

        View view= inflater.inflate(R.layout.home,null);
        ParserResult pr = new ParserResult();
        Button b=(Button) view.findViewById(R.id.home1);
        listview = (ListView)view.findViewById(R.id.lv_home);
        listview.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // TODO Auto-generated method stub
                Toast.makeText(getActivity(), "ullu ka patha", Toast.LENGTH_LONG).show();
                /*Profile frg3 = new Profile();
                Bundle b3 = new Bundle();
                String username = success_list3.get(position).getStorey_id();
                b3.putString("username", username);
                frg3.setArguments(b3);
                ((MainActivity)getActivity()).launchNewFragment(frg3, R.id.tab2);
                Toast.makeText(getActivity(), "Name :"+name ,1).show();*/
            }
        });

        et=(TextView) view.findViewById(R.id.editText1);
        b.setOnClickListener(this);

        if(ParserResult.success_list2.size() != 0){
            success_list3 = ParserResult.success_list2;
        }
        listview.setAdapter(new Adapters(success_list3 ,MainActivity.mainactivity_context));
        ParserResult.success_list2 = new ArrayList<SuccessStoreyItem>();
        return view;
    }

    @Override
    public void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        setTitle(R.string.Home);
    }
    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        name=et.getText().toString();
        Bundle bundle = new Bundle();
        bundle.putString("Name", name);

    Toast.makeText(getActivity(), "Name :"+name ,1).show();


        //((MainActivity)getActivity()).launchNewFragment(new Home2(),R.id.tab1);
    }


}
公共类人员扩展BaseFragment实现OnClickListener{
静态字符串名;
列表视图列表视图;
文本视图等;
静态公共列表成功_list3=新建ArrayList();
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
//TODO自动生成的方法存根
视图=充气机。充气(R.layout.home,空);
ParserResult pr=新的ParserResult();
按钮b=(按钮)视图.findViewById(R.id.home1);
listview=(listview)view.findViewById(R.id.lv_home);
setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父级、视图、,
内部位置,长id){
//TODO自动生成的方法存根
Toast.makeText(getActivity(),“ullu ka patha”,Toast.LENGTH_LONG.show();
/*外形frg3=新外形();
Bundle b3=新Bundle();
字符串username=success_list3.get(position.getStorey_id();
b3.putString(“用户名”,username);
frg3.设置参数(b3);
((MainActivity)getActivity()).launchNewFragment(frg3,R.id.tab2);
Toast.makeText(getActivity(),“Name:+Name,1.show()*/
}
});
et=(TextView)view.findViewById(R.id.editText1);
b、 setOnClickListener(此);
if(ParserResult.success_list2.size()!=0){
success_list3=ParserResult.success_list2;
}
setAdapter(新适配器(success_list3,MainActivity.MainActivity_context));
ParserResult.success_list2=新建ArrayList();
返回视图;
}
@凌驾
恢复时公开作废(){
//TODO自动生成的方法存根
super.onResume();
setTitle(R.string.Home);
}
@凌驾
公共void onClick(视图arg0){
//TODO自动生成的方法存根
name=et.getText().toString();
Bundle=新Bundle();
bundle.putString(“Name”,Name);
Toast.makeText(getActivity(),“Name:+Name,1.show();
//((MainActivity)getActivity()).launchNewFragment(new Home2(),R.id.tab1);
}
}
更新:添加了列表视图结构

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/view_imageview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/view_tv_username"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/view_imageview"
        android:layout_alignLeft="@+id/view_tv_age"
        android:layout_marginBottom="5sp"
        android:text="TextView" />

    <TextView
        android:id="@+id/view_tv_age"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/view_tv_username"
        android:layout_marginLeft="26dp"
        android:layout_toRightOf="@+id/view_imageview"
        android:text="TextView" />

    <ImageButton
        android:id="@+id/ib_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="29dp"
        android:layout_marginTop="18dp"
        android:background="#fff"
        android:src="@drawable/chevron" />

</RelativeLayout>

片段布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:padding="10sp" >


    <TextView
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="sp"
        android:gravity="center"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="New Machtes"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
        android:id="@+id/home1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/iconnew"
        android:textColor="#ffffff"
        android:text="16" />
</RelativeLayout>

    <ListView
        android:id="@+id/lv_home"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/relativeLayout1" >
    </ListView>

</RelativeLayout>

我认为在将onclickitemlistener()设置为该listview之前,应该先显示listview.setadapter()行及其相关数据。

解决方案
在make toast中将
android:genderantfocusability=“blocksDescendants”
添加到您的
中,尝试将getActivity()更改为getApplicationContext()发布列表项布局和适配器尝试将
android:genderantfocusability=“blocksDescendants”
添加到您的
@rogcg中非常感谢,它起到了作用。你能解释一下这里出了什么问题吗。附言:你可以加上我会接受的答案it@rogcg你知道它的相关第三方库吗?只是做了,但什么也没发生