0
arrayadapter에서 뷰 목록을 반환하는 listfragment가 있습니다. 필자는 액티비티의 listfragment 위에 다른 뷰 (스피너와 텍스트 뷰, 별도의 레이아웃 파일에 있음)가 있는지 알고 싶었습니다. 이를 달성하기 위해 레이아웃 파일을 어떻게 변경해야합니까? 어댑터에 대한Listfragment 위의 뷰 배치
rowlayout 파일 XML :보기를 포함
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!--Rank number-->
<TextView
android:id="@+id/rank"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/label"
android:textSize="40px"
/>
<!-- -->
<!--Device image-->
<ImageView
android:id="@+id/icon"
android:layout_width="60px"
android:layout_height="60px"
android:layout_marginLeft="15px"
android:layout_marginRight="10px"
android:layout_marginTop="4px"
android:layout_toRightOf="@+id/rank"
android:src="@drawable/ic_launcher" />
<!--Caption-->
<TextView
android:id="@+id/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/label"
android:layout_below="@+id/icon"
android:layout_marginLeft="25px"
/>
</RelativeLayout>
레이아웃 파일 topview.xml이 위에 배치 할 :
package com.example.listfragmentexample;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class SimpleArrayAdapter extends ArrayAdapter<String> {
//arrays and context
//call it to get information regarding another part of your program (activity, package/application)
Context context;
String ranks[];
String caption[] = new String[] {"LG G2", "HTC One", "Google Nexus 5", "iPhone 5s",
"Sony Xperia Z1 Compact", "Samsung Galaxy S4", "Samsung Galaxy Note 3", "Motorola Moto G", "BlackBerry Q10",
"Nokia Lumia 1020"};
int images[] = new int[] {R.drawable.ic_launcher};
//viewholder class
public class ViewHolder {
TextView rankView;
ImageView imageView;
TextView captionView;
}
public SimpleArrayAdapter(Context context, String[] ranks) {
super(context, R.layout.rowlayout, ranks);
this.context = context;
this.ranks = ranks;
}
//return multiple views
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//Layout inflater instantiates XML layout file
//get system service.
LayoutInflater inflater = (LayoutInflater) context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewHolder holder = new ViewHolder();
//get row view. xml file and root (parent)
//used with layout inflater
View rootView = inflater.inflate(R.layout.rowlayout, parent, false);
holder.rankView = (TextView) rootView.findViewById(R.id.rank);
holder.imageView = (ImageView) rootView.findViewById(R.id.icon);
holder.captionView = (TextView) rootView.findViewById(R.id.caption);
//set the data
holder.rankView.setText(ranks[position]);
/*holder.imageView.setImageResource(R.drawable.ic_launcher);*/
holder.captionView.setText(caption[position]);
return rootView;
}
}
The adapter is set in a listfragment class, which itself is started in another activity.
Happy to clarify and thanks in advance.