【发布时间】:2017-10-15 10:52:31
【问题描述】:
我正在测试制作每个选项卡具有不同内容的选项卡式布局。 在此选项卡中,我想在 Listview 中使用图像和文本进行布局。 这是我到目前为止编写的代码,但无法正常工作。
Layout_One.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.kreuzell.projecttest.MainActivity$PlaceholderFragment">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/menuText"/>
</RelativeLayout>
Layout_One.java
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.ImageView;
import java.util.List;
public class Layout_One extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.layout_one, container, false);
String[] menuText = {
"Text 1",
"Text 2",
"Text 3"
};
Integer[] menuImage = {
R.drawable.image_1,
R.drawable.image_2,
R.drawable.image_3
}
ListView listView = (ListView) rootView.findViewById(R.id.menuText);
ListView listView = (ListView) rootView.findViewById(R.id.menuImage);
ArrayAdapter<String> listViewAdapter = new ArrayAdapter<String>(
getActivity();
android.R.layout.simple_list_item_1,
menuText,
menuImage
)
listView.setAdapter(listViewAdapter);
return rootView;
}
}
我是新手,有人可以帮助我吗?谢谢
【问题讨论】:
标签: android android-layout listview android-fragments android-arrayadapter