我正在測試每個選項卡製作具有不同內容的選項卡式佈局。 在這個選項卡中,我希望使用Listview中的圖像和文本進行佈局。 這是我寫到目前爲止,但不工作的代碼。如何在片段佈局的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;
}
}
我新的這一點,任何人都可以幫我嗎?謝謝
如果你已經得到了你回答標記爲已回答 –