我有一个contextMenu它包含两个项目编辑和删除!但因为我正在写我的国家语言......项目应该是正确的! 以下是我的代码。请指导我。谢谢!
public class ListActivity extends AppCompatActivity {
ListView lst_data;
DicDBAdapter dicDBAdapter;
Dic dic;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
lst_data = (ListView) findViewById(R.id.lst_data);
dicDBAdapter = new DicDBAdapter(getApplicationContext());
ArrayList<String> arrayList = dicDBAdapter.getdata();
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_dropdown_item_1line,
arrayList);
lst_data.setAdapter(arrayAdapter);
registerForContextMenu(lst_data);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
getMenuInflater().inflate(R.menu.context, menu);
}
答案 0 :(得分:0)
使用以下代码创建布局文件。
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/dropDownItemStyle"
android:textAppearance="?android:attr/textAppearanceLargePopupMenu"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="start"
android:ellipsize="marquee" />
创建数组适配器时,将此布局作为项目传递。
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getApplicationContext(),
R.layout.new_layout,
arrayList);
答案 1 :(得分:0)
您可以在listView中更改layoutDirection
<ListView
android:layout_width="wrap_content"
android:layoutDirection="rtl"
android:layout_height="wrap_content"/>