我创建了一个使用自定义列表视图片段的应用程序。但自定义列表视图显示不正确。
下面附上我的屏幕截图。
这是我的单个行项的 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="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/Jobtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:paddingTop="2dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/green"
android:textStyle="bold" >
</TextView>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/Jobtitle"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<TextView
android:id="@+id/publishdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PubDate:-"
android:textColor="@color/textgrey"
/>
<TextView
android:id="@+id/lefttime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/publishdate"
android:layout_alignBottom="@+id/publishdate"
android:layout_alignParentRight="true"
android:text="Time Left:-"
android:textColor="@color/textgrey"
/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/relativeLayout1"
android:background="@drawable/dividr" >
</LinearLayout>
这是列表片段布局文件
<?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="wrap_content"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</ListView>
<TextView
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No text" >
</TextView>
这是我的适配器
package my.newapp.freelanceeye;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
public class joblisted extends ListFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapt my=new adapt(getActivity(), R.layout.listrow,m);
setListAdapter(my);
}
Context ctx;
public class adapt extends ArrayAdapter<String>{
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater=(LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row=inflater.inflate(R.layout.listrow,parent,false);
return row;
//return super.getView(position, convertView, parent);
}
public adapt(Context context, int textViewResourceId, String[] objects) {
super(context, textViewResourceId, objects);
ctx=context;
}
}
String[] m={"as","asa","sd","Ad","sad","asda"};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v=inflater.inflate(R.layout.listfragmnetlayout,container,false);
return v;
}
}