rafaxplayer
01/09/14, 09:06:24
saludos gente , tengo un problema con un list que no consigo establecer un view para cuando no hay datos , ya lo he echo otras veces pero en este caso no encuentro porque no lo muestra aunque parece todo estar bien.
mi código:
this.listView = ((ListView) findViewById(R.id.listView1));
RelativeLayout ly = (RelativeLayout)findViewById(R.layout.empty_list);
this.listView.setEmptyView(ly);
Esto seria el layout que quiero utilizar:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="150dp"
android:src="@drawable/ic_nodata" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:text="No Data"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColorHint="@color/LightGrey"
android:textColorLink="@color/DarkGray"
android:textStyle="bold" />
</RelativeLayout>
y el adapter que aplico despues:
public class NewPostAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public ArrayList<HashMap<String, String>> data;
private Context con;
static Typeface face;
public NewPostAdapter(Context context,
ArrayList<HashMap<String, String>> data) {
mInflater = LayoutInflater.from(context);
this.data = data;
this.con = context;
}
public HashMap<String, String> getItem(int position) {
return data.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.item_listview, null);
holder.txttitle = (TextView) convertView.findViewById(R.id.title);
holder.txtlastpostedname = (TextView) convertView
.findViewById(R.id.lastpostedname);
holder.txtnpostlast = (TextView) convertView
.findViewById(R.id.npostlast);
holder.txtnpostdate = (TextView) convertView
.findViewById(R.id.lastpostdate);
holder.txtforum = (TextView) convertView.findViewById(R.id.forum);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
// holder = (ViewHolder) convertView.getTag();
}
holder.txttitle.setText(data.get(position).get("title"));
// holder.txttitle.setTypeface(face);
holder.txtlastpostedname.setText("Author: "
+ data.get(position).get("postedname"));
holder.txtnpostlast.setText(data.get(position).get ("number"));
holder.txtnpostdate.setText(data.get(position).get ("datetime"));
holder.txtforum.setText(data.get(position).get("forum"));
return convertView;
}
static class ViewHolder {
TextView txttitle;
TextView txtlastpostedname;
TextView txtnpostlast;
TextView txtnpostdate;
TextView txtforum;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return data.size();
}
}
No se he probado de todo y no doy con el error, alguna sugerencia?
mi código:
this.listView = ((ListView) findViewById(R.id.listView1));
RelativeLayout ly = (RelativeLayout)findViewById(R.layout.empty_list);
this.listView.setEmptyView(ly);
Esto seria el layout que quiero utilizar:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="150dp"
android:src="@drawable/ic_nodata" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:text="No Data"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColorHint="@color/LightGrey"
android:textColorLink="@color/DarkGray"
android:textStyle="bold" />
</RelativeLayout>
y el adapter que aplico despues:
public class NewPostAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public ArrayList<HashMap<String, String>> data;
private Context con;
static Typeface face;
public NewPostAdapter(Context context,
ArrayList<HashMap<String, String>> data) {
mInflater = LayoutInflater.from(context);
this.data = data;
this.con = context;
}
public HashMap<String, String> getItem(int position) {
return data.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.item_listview, null);
holder.txttitle = (TextView) convertView.findViewById(R.id.title);
holder.txtlastpostedname = (TextView) convertView
.findViewById(R.id.lastpostedname);
holder.txtnpostlast = (TextView) convertView
.findViewById(R.id.npostlast);
holder.txtnpostdate = (TextView) convertView
.findViewById(R.id.lastpostdate);
holder.txtforum = (TextView) convertView.findViewById(R.id.forum);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
// holder = (ViewHolder) convertView.getTag();
}
holder.txttitle.setText(data.get(position).get("title"));
// holder.txttitle.setTypeface(face);
holder.txtlastpostedname.setText("Author: "
+ data.get(position).get("postedname"));
holder.txtnpostlast.setText(data.get(position).get ("number"));
holder.txtnpostdate.setText(data.get(position).get ("datetime"));
holder.txtforum.setText(data.get(position).get("forum"));
return convertView;
}
static class ViewHolder {
TextView txttitle;
TextView txtlastpostedname;
TextView txtnpostlast;
TextView txtnpostdate;
TextView txtforum;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return data.size();
}
}
No se he probado de todo y no doy con el error, alguna sugerencia?