I am trying to pass information to the next activity in my application based on which list view item was selected. However, startActivity is called when a custom button(id: button_go) is clicked.
I believe the common way to pass information based on which list view item is selected is through the following code:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long id){
Intent intent = new Intent(getActivity(), Detail_Activity.class);
}
});
But this does not work in my class as it is connected to a button. My code within my list View fragment follows.
class CustomAdapter extends BaseAdapter {
@Override
public int getCount() {
return testArray.length;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = getActivity().getLayoutInflater().inflate(R.layout.customlayout,null);
Button button_go = (Button)view.findViewById(R.id.button_go);
button_go.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
}
// Perform action on click
//startActivity(new Intent(getActivity(), Detail_Activity.class));
}
});
return view;
}
}
}