2016-04-05 210 views
1

我有一個contextMenu它包含兩個項目Edit和Delete!但是因爲我正在寫我的國家語言......項目應該是正確的對齊! 以下是我的代碼。請指導我,謝謝!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); 


} 

} enter image description here

回答

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); 
相關問題