Use the variable arg2 in the switch case.This indicates the position of the item which has been clicked.
using android ListView onItemClick to select specific Item in slide menu
题
OK guys, so after 4 hours of struggling i finally decided to ask here my problem. I developed a slide menu with a listView. I got the slide menu all good and i managed to make it doing just one action if one of the Items is clicked. My problem is that i do not know how to manage it further. I am thinking about making a switch case statement but the problem is that i cannot use "position" due to: "position cannot be resolved to a variable" Here is my list code so far:
public class RandomList extends SherlockListFragment{
String[] list_contents = {
"Add me on Google+",
"Linkedin",
"W&T Top Tips Forum",
};
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.list, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
final ListView list1;
list1 = getListView();
list1.setAdapter(new ArrayAdapter<String> (getActivity(),android.R.layout.simple_list_item_1, list_contents));
list1.setOnItemClickListener(
new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Object listItem = list1.getItemAtPosition(position);
//long index = arg0.getSelectedItemId();
switch(position){
}
Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
myWebLink.setData(Uri.parse("https://plus.google.com/u/0/115467961053443202630/about"));
startActivity(myWebLink);
}
}
);
}
}
解决方案
不隶属于 StackOverflow