2015-11-01 60 views
0

這是我的適配器的getView,它給每個項目錯誤的位置!所以我無法訪問我的物品細節。請幫我這個問題,我真的很困惑:-(getView給項目的錯誤位置

public class adapter_common extends ArrayAdapter<item> { 
private final Context context; 
@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
     LayoutInflater inflater = (LayoutInflater) context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     final View rowView = inflater.inflate(R.layout.post, parent, false); 
     Rowposition = position; 
     username.setText(itemsArrayList.get(position).getTitle()); 
     message_content.setText(itemsArrayList.get(position).getDes()); 
     like_count.setText(itemsArrayList.get(position).getLike() + " لایک"); 
     //row_pos.setText(itemsArrayList.get(position).getRow_pos()); 
     final String Like = itemsArrayList.get(position).getLike(); 
     btn_send.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
     }); 
     btn_save.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
      } 
     }); 

     btn_like.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
      } 
     }); 
     return rowView; 
    } 

public adapter_common(Context context, ArrayList<item> itemsArrayList) { 

    super(context, R.layout.post, itemsArrayList); 
    context = context; 
    this.context = context; 
    this.itemsArrayList = itemsArrayList; 
} 

}從我的應用程序

+0

發佈您的整個班級。不能承擔你的邏輯。 –

+0

我增加了詳細信息 –

+0

用戶名&message_content&like_count只是被替換每次,你沒有把他們從充氣的視圖android系統給你,爲什麼?那麼列表的要點是什麼? – j2emanue

回答

0

爲例,從getView

public SaldoProdutos getItem(int position) { 
    if (itemList != null) 
     return itemList.get(position); 
    return null; 
} 

    public View getView(final int position, View convertView, ViewGroup parent) { 

    View v = convertView; 
    v = null; 
    if (v == null) { 
     LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     v = inflater.inflate(R.layout.saldo_list_item, null); 
    } 

    SaldoProdutos produtos = itemList.get(position); 
    TextView Produtos = (TextView) v.findViewById(R.id.ProdutoSaldo); 
    Produtos.setText(""+produtos.descricao); 
    TextView Pontos = (TextView) v.findViewById(R.id.PontosSaldo); 
    Pontos.setText("" + produtos.pontos + " Pontos"); 
    ColorGenerator generator = ColorGenerator.MATERIAL; 
    int color1 = generator.getRandomColor(); 
    String inicial = (String) Produtos.getText(); 
    TextDrawable drawable = TextDrawable.builder().buildRound(inicial.substring(0,1), color1); 
    ImageView imagem = (ImageView) v.findViewById(R.id.iconecliente); 
    imagem.setImageDrawable(drawable); 

    if (mSelectedItemsIds.get(position)) 
    { 


     ImageView check = (ImageView) v.findViewById(R.id.check); 
     v.setBackgroundColor(HIGHLIGHT_COLOR); 
     TextDrawable drawable1 = TextDrawable.builder().buildRound(" ", 0xff616161); 
     imagem.setImageDrawable(drawable1); 
     check.setVisibility(View.VISIBLE); 
    } 

    else { 




     ImageView check = (ImageView) v.findViewById(R.id.check); 
     v.setBackgroundColor(Color.TRANSPARENT); 
     String inicial1 = (String) Produtos.getText(); 
     TextDrawable drawable1 = TextDrawable.builder().buildRound(inicial1.substring(0, 1), color1); 
     ImageView imagem1 = (ImageView) v.findViewById(R.id.iconecliente); 
     imagem1.setImageDrawable(drawable1); 
     check.setVisibility(View.GONE); 
    } 



    return v; 

} 
在活動或片段

你做adapter.getItem方法(位置)

0

正在使用Rowposition變得可導航到細節?

我想這是一個全局變量,它保存'position'的最後一個被調用的值,並幾乎返回使用它的錯誤索引。取而代之的是使position變成final,並在clickListeners中使用它。

問候,
sha

相關問題