Я занимаюсь разработкой приложения с вкладками. На одной из вкладок
У меня есть два поля EditText
и пара кнопок. Я хочу добавить ExpandableListView
на вкладку, под остальными элементами.
Моя проблема в том, что текущий класс расширяется Activity
. Все примеры, которые я нашел, расширяют ExpandableListActivity
, но я не могу расширить оба для одного класса.
Как я могу добавить этот список на вкладку? Я добавил элемент ExpandableListView
в файл XML
, но всякий раз, когда я запускаю его, он не отображается. Я понимаю, что мне нужно привязать представление к некоторым данным, но как мне это сделать?
Спасибо.
Вот мой код класса:
public class DirectionsTab extends Activity
{
private Button clear_btn;
private Button go_btn;
private EditText origin_txt;
private EditText dest_txt;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.directions_tab);
// initialize views and onClick event handler
origin_txt = (EditText)findViewById(R.id.origin_txt);
dest_txt = (EditText)findViewById(R.id.dest_txt);
clear_btn = (Button)findViewById(R.id.clear_btn);
// clear all text fields and return focus to dest_txt
clear_btn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v)
{
origin_txt.setText("");
dest_txt.setText("");
origin_txt.requestFocus();
}
});
} // end public void onCreate(Bundle savedInstanceState)
} // end public class DirectionsTab extends Activity
и XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/origin_lbl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Origin"/>
<EditText
android:id="@+id/origin_txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/origin_lbl"/>
<TextView
android:id="@+id/dest_lbl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/origin_txt"
android:text="Destination" />
<EditText
android:id="@+id/dest_txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/dest_lbl" />
<ExpandableListView
android:id="@+id/listView"
android:layout_below="@+id/dest_txt"
android:layout_height="wrap_content"
android:layout_width="wrap_content" /><!--android:id="@android:id/list"-->
<Button style="?android:attr/buttonStyleSmall"
android:id="@+id/clear_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/dest_txt"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:layout_marginTop="10dip"
android:text="Clear" />
<Button style="?android:attr/buttonStyleSmall"
android:id="@+id/go_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/clear_btn"
android:layout_alignTop="@id/clear_btn"
android:text="Go!" />
</RelativeLayout>