Clickable Listview In Fragment
I am trying to create a simple clickable listview in a fragment. (not a listfragment) So when you click a item it goes to a new detailpage about that item. I got the listview worki
Solution 1:
You need to add an OnItemClickListener to your list.
list.setOnItemClickListener(newOnItemClickListener() {
@OverridepublicvoidonItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Log.v("TAG", "CLICKED row number: " + arg2);
}
});
The row you clicked is in arg2.
Solution 2:
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Viewview= inflater.inflate(R.layout.fragment_biblio, container, false);
ListViewlist= (ListView)view.findViewById(R.id.listView1);
ArrayAdapter<String> adapter = newArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, items);
list.setAdapter(adapter);
list.setOnItemClickListener(newOnItemClickListener()
{
@OverridepublicvoidonItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intentintent=newIntent(MainActivity.this, nextActivity.class);
startActivity(intent);
}
});
return view;
}
Post a Comment for "Clickable Listview In Fragment"