連絡先のリスト全体 (長いリスト) を表示する ListView を含むレイアウトを作成する方法が見つからないようです。リストの下に 2 つのボタンが並んでいます。
それは私を怖がらせます、私がしていることは何もうまくいかないようです。私はいくつかの関連する質問を検索し、これを見つけました:ListViewとButtonsを備えたAndroidレイアウト ですが、そこにある代替ソリューションはどれも私のために働いていません.
(Eclipse の) グラフィック表示を見ると問題ないように見えますが、自分のデバイスで実行すると、連絡先のリストしか表示されません。listView はボタンに重なっています。
行を表す別のレイアウトでレンダリングする simpleList を使用しています。Javaコードを実行したところ、話していた activity_contact_list についての言及が見つからなかったため、プログラムで何かが台無しになっているのではないかと疑い始めています。行レイアウトへの接続のみ。
だから私はこの activity_contact_list.xml を手に入れました:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/contact_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_alignParentTop="true" >
</ListView>
<LinearLayout
android:id="@+id/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="1.0"
android:orientation="horizontal" >
<Button
android:id="@+id/action_cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancle" />
<Button
android:id="@+id/action_add"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Add" />
</LinearLayout>
</LinearLayout>
これは、LinearLayout の代わりに RelativeLayout を使用する、ボタンの LinearLayout の下に ListView のコードを配置するなど、多くの試行を重ねた結果です。
アクティビティのコードは次のとおりです: ContactList.java:
public class ContactList extends ListActivity{
//some global variables for late use.
public Model model;
SimpleAdapter adapter;
List<Map<String, String>> data; /* data is a list of Map */
String[] from = {"name","phone"}; /* names of the columns */ //TODO - add date!
int[] to = {R.id.name, R.id.number};
List<Contact> contacts; /* list of contacts */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_contact_list);
// Set up the action bar.
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayHomeAsUpEnabled(true);
model = Model.getInstance(this);
data = new ArrayList<Map<String, String>>();
contacts = fillContactsList();
fill_data();
adapter = new SimpleAdapter(this, data, R.layout.contact_list_row, from, to);
setListAdapter(adapter);
}
setContentView
他の方法ではコンパイルできないため、その行にコメントを付けました...
言われるとおりです。リストは完全に機能します。ただし、アクティビティの下部にあるボタンと重なっています。何か案が?私はそれが何かばかげていると確信しています..
前もって感謝します!