asim abbasi asim abbasi - 9 days ago 6
Android Question

ListView Click in android fragment

I can't move from

fragment
to
Activity
on ListItem Click Listener i think i am doing it right but don't know where is problem.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveInstanceState) {
return inflater.inflate(R.layout.scholorship_listing_main,container,false);
}

@Override
public void onStart() {


super.onStart();


list=(ListView)getActivity().findViewById(R.id.Scholorshiplist);
setAdapterValue();


list.setOnItemClickListener(new AdapterView.OnItemClickListener()

{


@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(getActivity(), ScholorshipDetail.class);
getActivity().startActivity(intent);
//getActivity().finish();
}
});

}


And my
Activity
class on which I want to move is

public class ScholorshipDetail extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scholorship_detail);
}
}


and my xml is:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.temp.scholorshipapp.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Scholorships"
android:textColor="@color/black"
android:textSize="25sp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="80dp"
android:layout_centerHorizontal="true"
android:id="@+id/txt_scholorship"
android:divider="#C0C0C0"
android:dividerHeight="4px"/>

<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@android:color/black"
android:layout_below="@+id/txt_scholorship"/>

<ListView
android:layout_below="@id/txt_scholorship"
android:id="@+id/Scholorshiplist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#C0C0C0"
android:dividerHeight="4px"

/>
</RelativeLayout>

Answer

This might be your adapter layout contains the click listener view.i.e, button view or some other view, which will block the listview click listner. So in your adapter parent layout you need add block descendent or focusability as below,

android:descendantFocusability="blocksDescendants"
(OR)
android:focusable="false"

Hope this is helpful:)