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);
}
}
);
}
}
答案 0 :(得分:0)
在开关盒中使用变量arg2。这表示已点击的项目的位置。