Я использую следующий файл main.xml для своего приложения.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/toplinear">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/linear">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Previous"
android:id="@+id/previous"
android:layout_weight="1"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Next"
android:id="@+id/next"
android:layout_toRightOf="@id/previous"
android:layout_weight="1"
/>
</LinearLayout>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/android:list"
android:layout_weight="10"
/>
</LinearLayout>
Я хочу иметь 2 кнопки сверху, предыдущую и следующую, и мой список с пользовательским адаптером под ним.Несколько дней назад у меня был только мой ListView, показывающий кнопки.Теперь я, кажется, застрял на другой стороне, где мой список не отображается, в то время как мои кнопки видят.
Моя деятельность распространяется на ListActivity и использует этот код для заполнения его привычным адаптером.
ListView lv = getListView();
lv.setAdapter(new MyCustomAdapter(this, R.layout.custom_list, nameResults));
public class MyCustomAdapter extends ArrayAdapter<String> {
private String[] nameResults;
private Context context;
public MyCustomAdapter(Context context, int textViewResourceId,
String[] names) {
super(context, textViewResourceId, names);
this.context = context;
nameResults = names;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.custom_list, parent, false);
}
TextView label = (TextView) row.findViewById(R.id.Name);
label.setText(nameResults[position]);
TextView descr = (TextView) row.findViewById(R.id.Description);
descr.setText(linkedResults.get(nameResults[position]));
return row;
}
}
Я пытался использовать "lv.addHeaderView (previous);"но это только дало мне смутные ClassCastException для LayoutParams.
Я думаю, что моя проблема в настоящее время находится в моем main.xml, так как на вкладке Layout в Eclipse она также не будет отображать ListView.Он знает его там, как он отображается на вкладке структуры, но визуальное представление не выделяет его красным контуром, когда я его выбираю.
Для полноты, мой макет custom_list (он же строка) xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/Name"
android:textColor="#000000"
android:textStyle="bold"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/Description"
android:textColor="#000000"
/>
</LinearLayout>