Home > Mobile >  Consult, how to set up a listview context menu style, let him can be fully displayed
Consult, how to set up a listview context menu style, let him can be fully displayed

Time:10-12

As shown in figure, according to the listview long one, the pop-up context menu, the pop-up menu in some position can not be completely, according to the need to scroll menu of the scroll bar, how can let he fully displayed,
The following is the source code

Package com. Example. Contextmunu;

Import the Java. Util. ArrayList;
Import the Java. Util. Collections;
import java.util.List;

The import android. App. ListActivity;
The import android. Graphics. Color;
The import android. OS. Bundle;
The import android. Support. The v4. View. ViewCompat;
The import android. View. ContextMenu;
The import android. View. ContextMenu. ContextMenuInfo;
The import android. View. The Menu;
The import android. View. MenuItem;
The import android. View. The view;
The import android. View. The view. OnCreateContextMenuListener;
The import android. View. ViewGroup;
The import android. Widget. BaseAdapter;
The import android. Widget. LinearLayout;
The import android. Widget. TextView;

Public class MainActivity extends ListActivity {
Private class ViewHolder {
Public TextView index;
Public TextView name;

Private ViewHolder () {
}
}

Private class UserListAdapter extends BaseAdapter {
Private List FriendList=new ArrayList (a);

Public long getItemId (int I) {
Return (long) I;
}

UserListAdapter () {
FriendList. Add (" * * ");
FriendList. Add (" li si ");
FriendList. Add (" two pock-marked ");
FriendList. Add (" * * ");
FriendList. Add (" li si ");
FriendList. Add (" two pock-marked ");
FriendList. Add (" * * ");
FriendList. Add (" li si ");
FriendList. Add (" two pock-marked ");
FriendList. Add (" * * ");
FriendList. Add (" li si ");
FriendList. Add (" two pock-marked ");
}

Public int getCount () {
Return this. The friendList. The size ();
}

Public String the getItem (int I) {
Return (String) enclosing friendList. Get (I);
}

Public View getView (int, View View and ViewGroup ViewGroup) {
ViewHolder ViewHolder=null;
If (view==null) {
View=the inflate (MainActivity. Enclosing getApplicationContext (), R.l ayout. Item_users, null);
ViewHolder=new viewHolder ();
ViewHolder. Index=(TextView) view. The findViewById (R.i d.i tem_index);
ViewHolder. Name=(TextView) view. The findViewById (R.i d.i tem_name);
The setTag (viewGroup);
} else {
ViewHolder=(viewHolder) the getTag ();
}
ViewHolder. Index. SetText (String. The valueOf (I + 1));
ViewHolder. Name. SetText (the getItem (I));
Return the view;
}
}

@ Override
Protected void onResume () {
SetListAdapter (new UserListAdapter ());
Super. OnResume ();
}

@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GetListView (). SetOnCreateContextMenuListener (new OnCreateContextMenuListener () {
@ Override
Public void onCreateContextMenu (ContextMenu ContextMenu, View arg1, ContextMenuInfo arg2) {
ContextMenu. SetHeaderTitle (" operate ");
ContextMenu. Add (0, 0, 0, "1111111111111");
ContextMenu. Add (0, 1, 0, "222222222222222222");
ContextMenu. Add (0, 2, 0, "333333333333333333");
}
});
}

@ Override
Public Boolean onCreateOptionsMenu (Menu Menu) {
//to Inflate the menu; This adds the items to the action bar if it is present.
GetMenuInflater (). Inflate (R.m emu. Main, menu).
return true;
}

@ Override
Public Boolean onOptionsItemSelected (MenuItem item) {
//Handle The action bar item on here. The action bar will
//automatically handle on on the Home/the Up button, so long
//as you specify a parent activity in AndroidManifest. XML.
Int id=item. GetItemId ();
If (id==da ction_settings R.i) {
return true;
}
Return super. OnOptionsItemSelected (item);
}
}

CodePudding user response:

Oneself the top, to prevent heavy stick

CodePudding user response:

Can use a Dialog displays

CodePudding user response:

Do you feel weird this logic, the item was always on time can play a DialogFragment (you can see I write BaseDialog oh), can use the popupwindow play menu

CodePudding user response:

Solve the problem? I also appeared such
In the top bar contextmenu show is not complete