I have a Custom Listview but i’m running into a weird issue when I click one item: it only responds when I click on the text itself, it doesn’t work on the whole “rectangle”
this is my listelement.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:minHeight="20dip"
/>
and this is the java code:
public class TabFragment5 extends ListFragment {
/** (non-Javadoc)
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
*/
String[] month ={
"January ",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListAdapter myListAdapter = new ArrayAdapter<String>(
getActivity(),
R.layout.listelement,
month);
setListAdapter(myListAdapter);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.tab_frag5_layout, container, false);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
Toast.makeText(
getActivity(),
getListView().getItemAtPosition(position).toString(),
Toast.LENGTH_LONG).show();
}
}
Nevermind the silly program, i’m just running a tutorial for now. Any hints on how to make it work on the whole list item rectangle? Thanks
ListFragment already has a ListView in it, so you may not need to inflate a layout from onCreateView unless you are making a custom layout that has a ListView inside it. I imagine your problem is in your layout for tab_frag5_layout. Whatever you are wrapping the ListView in is probably shrinking the width of the ListView.
Combining your onCreate and onCreateView into a onActivityCreated implementation worked for me.
}