1

My custom listview is showing empty rows but when i use logcat to display the data it shows that the data is all there in my arraylist...how do i make the listview show my arraylist items?

public class Myarrayadapter extends ArrayAdapter<String> {

Context context;
ArrayList<String> values;
int resid;

public Myarrayadapter(Context context, int resid, ArrayList<String> values) {
    super(context, resid, values);
    this.resid = resid;
    this.context = context;
    this.values = values;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(resid, parent, false);
    return rowView;
}
}

CLASSS HERE ////////////////////////////////////////////

    final ListView HomeListView = (ListView) findViewById(R.id.HomeListView);
    String[] filelist = fileList();
    ArrayList<String> fileList = new ArrayList<String>();

    for (int i=0; i < filelist.length; i++) {//displays only first half of job number
          String[] stemp = filelist[i].split("\\.");
        if(!fileList.contains(stemp[0])) {//makes sure only one job number is show in the list
            fileList.add(stemp[0]);
        }
    }
    Collections.reverse(fileList);
    Myarrayadapter listAdapter = new Myarrayadapter(this, R.layout.homelistview, fileList);
    HomeListView.setAdapter(listAdapter);
    HomeListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //get the clicked items job no. and pass it to the next activity which will display all relevant jobs
            Intent detailedlist_intent = new Intent(Home.this, Home2.class);
            detailedlist_intent.putExtra("Jobno", HomeListView.getItemAtPosition(position).toString());
            startActivity(detailedlist_intent);
        }
    });
Unihedron
  • 10,902
  • 13
  • 62
  • 72
Douglas Johgn
  • 221
  • 3
  • 10
  • 1
    Are you setting the adapter on your list? – kha Dec 03 '14 at 08:57
  • Check : http://stackoverflow.com/questions/19079400/arrayadapter-in-android-to-create-simple-listview – Haresh Chhelana Dec 03 '14 at 09:01
  • 1
    you are Inflating the view but never set any values, so if the xml view (resid) is empty or have textViews that is empty too you will get empty rows?! – Yazan Dec 03 '14 at 09:06

2 Answers2

1

for creating a custom list 1Create Model to save data for each listview row. 2. Save data to Model. 3. Take each Model class object in an ArrayList. 4. Create Custom adapter. Pass Arraylist to adapter. Adapter called recursively for each listview row and get data from Model inside ArrayList. 5. Call xml file inside Adapter for each Listview row ( Use of LayoutInflater inside Adapter ). 6. Inside MainActivity Set Adapter to ListView 7. Define List in AnadroidMainifest.xml file

for reference you can use below link

http://androidexample.com/How_To_Create_A_Custom_Listview_-_Android_Example/index.php?view=article_discription&aid=67&aaid=92
anupam sharma
  • 1,705
  • 17
  • 13
1

You Should set the value to the textview inside the resid layout. you are not setting the text to textview. thats why its coming as empty.

MathanG
  • 1,195
  • 10
  • 22