我有一排要填充列表视图的按钮。看起来像这样:
按钮1 | 按钮2 | 按钮3 | 按钮4
清单项目 1
清单项目 2
清单项目 3
如果我按下 Button1,我将显示一个视图,如果我选择 Button2,我将显示另一个视图。我有没有选择按钮的列表视图。但是,我想选择一个按钮并根据所选按钮填充一个 listveiw。这只是我的第二个应用程序,所以我可能会以错误的方式进行操作。
这是我的布局文件:
<LinearLayout
android:layout_weight="2"
android:layout_height="fill_parent"
android:layout_width="match_parent"
>
<VideoView
android:id="@+id/video_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:orientation="horizontal" >
<Button
android:id="@+id/chapters"
android:layout_width="wrap_content"
android:layout_height="@dimen/btn_layout_height"
android:textSize="@dimen/text_size"
android:background="@drawable/button_custom"
android:text="@string/chapters" />
<Button
android:id="@+id/scales"
android:layout_width="100dp"
android:layout_height="@dimen/btn_layout_height"
android:textSize="@dimen/text_size"
android:background="@drawable/button_custom"
android:text="@string/scales" />
<Button
android:id="@+id/b_flat"
android:layout_width="wrap_content"
android:layout_height="@dimen/btn_layout_height"
android:textSize="@dimen/text_size"
android:background="@drawable/button_custom"
android:text="@string/b_flat" />
<Button
android:id="@+id/e_flat"
android:layout_width="75dp"
android:layout_height="@dimen/btn_layout_height"
android:textSize="@dimen/text_size"
android:background="@drawable/button_custom"
android:text="@string/e_flat" />
<Button
android:id="@+id/concert"
android:layout_width="wrap_content"
android:layout_height="@dimen/btn_layout_height"
android:textSize="@dimen/text_size"
android:background="@drawable/button_custom"
android:text="@string/concert" />
<Button
android:id="@+id/bass"
android:layout_width="75dp"
android:layout_height="@dimen/btn_layout_height"
android:textSize="@dimen/text_size"
android:background="@drawable/button_custom"
android:text="@string/bass" />
<Button
android:id="@+id/video"
android:layout_width="wrap_content"
android:layout_height="@dimen/btn_layout_height"
android:textSize="@dimen/text_size"
android:background="@drawable/button_custom"
android:text="@string/video" />
<Button
android:id="@+id/practice"
android:layout_width="wrap_content"
android:layout_height="@dimen/btn_layout_height"
android:textSize="@dimen/text_size"
android:background="@drawable/button_custom"
android:text="@string/practice" />
</LinearLayout>
<FrameLayout
android:id="@+id/fragmentContainer"
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
</LinearLayout>
我想选择“章节”按钮并填充列表按钮或选择“音乐会”并填充列表视图。
我不知道在哪里或如何设置按下按钮。这是我尝试失败的方法:
public class ChapterListFragment extends ListFragment {
private static final boolean VERBOSE = true;
private ArrayList<Chapters> mChapters;
private static final String TAG = "ChapterListFragment";
private Button mChaptersButton;
@Override
public void onCreate(Bundle savedInstanceState) {
if (VERBOSE) Log.v(TAG, "+++ onCreate +++");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_improvisation);
mChaptersButton = (Button)v.findViewById(R.id.chapters);
mChaptersButton.setPressed(true);
getActivity().setTitle(R.string.chapters_title);
mChapters = ChapterList.get(getActivity()).getChapters();
ChapterAdapter adapter = new ChapterAdapter(mChapters);
setListAdapter(adapter);
}
这不起作用,因为我不能在 ListFragment 中使用 SetContentView。此外,按钮没有焦点。任何建议将不胜感激