하나의 탭에 4 개의 탭이있는 조각이 있습니다. 목록보기를 표시해야합니다. 나는이 코드를 멀리 가지고 있지만 몇 가지 오류가 있고 내가 제대로하지 않거나 간단한 것을 놓친다면 확실하지 않다. 여기에 내가이안드로이드의 조각에 이미지가있는 목록보기를 표시하는 방법
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.listview_layout, from, to);
및
ListView listView = (ListView) findViewById(R.id.listview);
에서 이러한 코드 두 줄에 오류를 얻고있다
public class SupportFragment extends SherlockFragment{
String[] supporters = new String[] {
"Gulf Shores",
"Central",
"Spanish Fort",
"Jackson Heights",
"Summerdale",
"Atlas",
"Robertsdale",
"Eastern Shore"
};
int[] images = new int[] {
R.drawable.gulfshores,
R.drawable.central,
R.drawable.spanishfort,
R.drawable.jacksonheights,
R.drawable.summerdale,
R.drawable.atlas,
R.drawable.robertsdale,
R.drawable.easternshore
};
String[] church = new String[]{
"Chruch of Christ",
"Chruch of Christ",
"Chruch of Christ",
"Chruch of Christ",
"Chruch of Christ",
"Chruch of Christ",
"Chruch of Christ",
"Chruch of Christ"
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.tab_support_layout, null);
List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
for(int i=0;i<10;i++){
HashMap<String, String> hm = new HashMap<String,String>();
hm.put("sup", "Supporters : " + supporters[i]);
hm.put("chur","Church : " + church[i]);
hm.put("icon", Integer.toString(images[i]));
aList.add(hm);
}
String[] from = {"sup", "chur", "icon"};
int[] to = {R.id.icon, R.id.sup, R.id.chur};
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.listview_layout, from, to);
ListView listView = (ListView) findViewById(R.id.listview);
listView.setAdapter(adapter);
return root;
}
}
조각 활동을 사용하고 내 코드입니다 내가 얻는 오류는 다음과 같습니다.
있어서 getBaseContext()가 입력 SupportFragment
있어서 findViewById를 (INT)에 대해 정의되지는 입력 SupportFragment리스트 뷰
<?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:orientation="vertical"
android:background="@drawable/tableback" >
<TextView
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
위한
XML 및리스트 뷰 레이아웃 정의되지
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/sup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
/>
<TextView
android:id="@+id/chur"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"
/>
</LinearLayout>
</LinearLayout>
도움을 주시면 큰 도움이됩니다.
오른쪽 내가 모르는 :
그런 다음이 같은
findViewById
를 호출 할 수 있습니다 getActivity()는 오류를 해결하기 위해 노력했지만 findViewById를 사용하려면 뷰를 부 풀릴 때 100 % 확신하지 못합니다. 이 작업을 수행하는 데 사용하는 좋은 방법인지 확실하지 않습니다. 그것에 대한 생각을 가지고 있거나 뷰를 부 풀릴 수있는 방향으로 나를 가리킬 수 있습니까? – Bryan모든 조각을 처리하는 조각 활동이 있습니다. 이것은 처리하는 조각 중 하나입니다. – Bryan
@Bryan이 게시물을 편집했습니다. – Ahmad