Android : how to get position data of listview in android

on Thursday, October 9, 2014


i m new on android i have displayed jsonarray in listview working well i implemented onitemclick of Listview... item click is Performing ..But When I want get postion data from array list


i tried Like This But Could not Get Any Data from array list


here is my code



listview.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {

/// UNABLE TO GET DATA FROM ARRAY LIST
RequesterId=String.valueOf(arraylist.get(position).get("user_id"));
final CharSequence[]items = {"Add as Friend", "Cancel", "View Profile"};

AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.AlertDialogCustom));
//Set its title

/* builder.setTitle("Request Confirmation");*/
//Set the list items and assign with the click listener
builder.setItems(items, new DialogInterface.OnClickListener() {
// Click listener
public void onClick(DialogInterface dialog, int item) {

switch(item){
case 0:// first item in your LIST
Toast.makeText(getActivity(), "Add as Friend", Toast.LENGTH_SHORT).show();
// new Acceptaccess().execute();
break;
case 1:// second item in your LIST
Toast.makeText(getActivity(), "Cancel", Toast.LENGTH_SHORT).show();
// new CancelRequest().execute();
break;
case 2:// third item in your LIST
new userbyid().execute();
Toast.makeText(getActivity(), "View Profile", Toast.LENGTH_SHORT).show();
break;

}

}
});
AlertDialog alert = builder.create();
//display dialog box
alert.show();



}
});

0 comments:

Post a Comment