Show context menu layout on top of app layout using list item longclicklistener

77 Views Asked by At

I want to show context menu on the top of app layout overlapping toolbar in an Android app. When a user hold long tap on a list item using a listview, the context menu shown on top of the app layout with some menu option. Image is attached for more clearance please.

public class FileActivity extends ListActivity {

String str;
ArrayList<String> al;
ArrayAdapter<String> adapter;
ListView lv;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.file_view);

Intent int1=getIntent();
ArrayList<String> 
arr1=GetFiles(Environment.getExternalStorageDirectory().getPath());
adapter= new ArrayAdapter<String>(getApplicationContext(),
                        
android.R.layout.simple_expandable_list_item_1,arr1);

lv = (ListView) findViewById(android.R.id.list);
lv.setAdapter(adapter);
}  

private ArrayList<String> GetFiles(String path) {
ArrayList<String> arr2=new ArrayList<String>();
File file=new File(path);
File[] allfiles=file.listFiles();
if(allfiles.length==0) {
    return null;
}
else {
    for(int i=0;i<allfiles.length;i++) {
        arr2.add(allfiles[i].getName());
    }
}
return arr2; 
}


@Override
protected void onListItemClick(ListView l, View v, int position, long 
id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
}

See the example picture here

0

There are 0 best solutions below