2016-10-25 21 views
0

私のフラグメントからリストビューを表示するために私のアダプタにいくつかの情報を渡そうとしているが、それは成功しますが、リストビューは何も表示しません。 私は以下のCustomAdapterクラスを付けています。なぜ私はリストビューをアンドロイドで見ることができませんか?

package com.example.rama.hello.Adapters;

import android.app.Activity; 
import android.content.Context; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.BaseAdapter; 
import android.widget.ImageView; 
import android.widget.TextView; 
import com.example.rama.hello.Bean.RowItem; 
import com.example.rama.hello.R; 

import java.io.File; 
import java.util.ArrayList; 
import java.util.List; 

/** 
* Created by RAMA on 10/25/2016. 
*/ 
public class CustomAdapter extends ArrayAdapter<RowItem> { 

    Context mcontext; 
    ArrayList<RowItem> rowItem = new ArrayList<RowItem>(); 
    private RowItem row; 
    RowItem data; 


    public CustomAdapter(Context context, int resourceId, 
           ArrayList<RowItem> items) { 
     super(context, resourceId, items); 
     this.mcontext = context; 
    } 

    @Override 
    public int getCount() 
    { 
     return rowItem.size(); 
    } 


    @Override 
    public long getItemId(int position) { 
     return rowItem.indexOf(getItem(position)); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) 
    { 
     if (convertView == null) 
     { 
      LayoutInflater mInflater = (LayoutInflater) mcontext 
        .getSystemService(Activity.LAYOUT_INFLATER_SERVICE); 
      convertView = mInflater.inflate(R.layout.list_item,parent,false); 
     } 

     ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon); 
     TextView txtTitle = (TextView) convertView.findViewById(R.id.title); 
     TextView txtSubTitle = (TextView) convertView.findViewById(R.id.sub_title); 
     TextView txtRightTitle = (TextView) convertView.findViewById(R.id.right_title); 

     RowItem row_pos = getItem(position); 

     // setting the image resource and title,subtitle,Righttitle 
     File imgFile = new File(row_pos.getIcon()); 

     if(imgFile.exists()){ 

      Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); 
      imgIcon.setImageBitmap(myBitmap); 
     } 


     if(row_pos.getTitle() == " ") 
     txtTitle.setText(row_pos.getPhone_number()); 
     else 
     txtTitle.setText(row_pos.getTitle()); 

     txtSubTitle.setText(row_pos.getSub_title()); 
     txtRightTitle.setText(row_pos.getRight_title()); 

     return convertView; 
    } 
} 
+1

この記事の明確化と関連したコメントを残しておきましょう。接線の説明は避けてください。ありがとうございました。 –

答えて

1

ArrayAdapterでは、あなたが必要とするすべてはgetViewArrayAdapterをオーバーライドすることで、これがないために作られたArrayAdapterである、(RowItemのあなたのケースリストに)項目のリストのための参照を取得する必要はありません。

public class CustomAdapter extends ArrayAdapter<RowItem> { 


    public CustomAdapter(Context context, int resourceId, 
         ArrayList<RowItem> items) { 
     super(context, resourceId, items); 
    } 


    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     if (convertView == null) { 
     LayoutInflater mInflater = LayoutInflater.from(parent.getContext()); 
     convertView = mInflater.inflate(R.layout.list_item, parent, false); 
     } 

     ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon); 
     TextView txtTitle = (TextView) convertView.findViewById(R.id.title); 
     TextView txtSubTitle = (TextView) convertView.findViewById(R.id.sub_title); 
     TextView txtRightTitle = (TextView) convertView.findViewById(R.id.right_title); 

     RowItem row_pos = getItem(position); 

     // setting the image resource and title,subtitle,Righttitle 
     File imgFile = new File(row_pos.getIcon()); 

     if (imgFile.exists()) { 

     Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); 
     imgIcon.setImageBitmap(myBitmap); 
     } 


     if (row_pos.getTitle() == " ") 
     txtTitle.setText(row_pos.getPhone_number()); 
     else 
     txtTitle.setText(row_pos.getTitle()); 

     txtSubTitle.setText(row_pos.getSub_title()); 
     txtRightTitle.setText(row_pos.getRight_title()); 

     return convertView; 
    } 
    } 
関連する問題