Reputation: 2541
i am trying to bind a custom list view in my app from sqlite database. Data fetched from db successfully and activity execute without any error but displaying blankactivity . Here is the code please suggest where is the issue and how to fix it? This is display adapter
package com.example.automaticprofilechanger;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class DisplayAdapter extends BaseAdapter {
private Context mContext;
private ArrayList<String> id;
private ArrayList<String> profile_Name;
private ArrayList<String> profile;
private ArrayList<String> time;
public DisplayAdapter(Context c, ArrayList<String> id,ArrayList<String> Profile_Name, ArrayList<String> Profile, ArrayList<String> Time) {
this.mContext = c;
this.id = id;
this.profile_Name = Profile_Name;
this.profile = Profile;
this.time = Time;
}
public int getCount() {
return id.size();
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int pos, View child, ViewGroup parent) {
Holder mHolder;
LayoutInflater layoutInflater;
if (child == null) {
layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
child = layoutInflater.inflate(R.layout.listcell, null);
mHolder = new Holder();
mHolder.txt_Profile_Name = (TextView) child.findViewById(R.id.txt_Profile_Name);
mHolder.txt_Profile = (TextView) child.findViewById(R.id.txt_Profile);
mHolder.txt_Time = (TextView) child.findViewById(R.id.txt_Time);
child.setTag(mHolder);
} else {
mHolder = (Holder) child.getTag();
}
mHolder.txt_Profile_Name.setText(profile_Name.get(pos));
mHolder.txt_Profile.setText(profile.get(pos));
mHolder.txt_Time.setText(time.get(pos));
return child;
}
public class Holder {
TextView txt_Profile_Name;
TextView txt_Profile;
TextView txt_Time;
}
}
Here is the Code where using Display Adapter
private void displayData() {
List<Time> obj= db.getAllTime();
for (Time time : obj) {
_Profile_Name.add(time._profilename);
_profile.add(time._profile);
_Time.add(time._time);
}
DisplayAdapter disadpt = new DisplayAdapter(ListTimeActivity.this,_id,_Profile_Name, _profile,_Time);
list.setAdapter(disadpt);
db.close();
}
Upvotes: 0
Views: 92
Reputation: 133560
From your comments
id.size() is 0
So its natural you don't see the list populated by data.
You need to make sure you add items to arraylist id before passing it to the constructor of adapter class
You are returning null in getItem
@Override
public Object getItem(int position) {
return id.get(position);
}
@Override
public long getItemId(int position) {
return id.indexOf(getItem(position));
}
Upvotes: 0