基本的に私がやりたいことは次のとおりです。自分のアプリケーションにカスタムリストアダプターのリストビューがあります。しかし、私はTextLabelを呼び出し元のアクティビティに基づいて変更したい。商品リスト、お気に入り、履歴のような3つのリストがあります。だから私たちが呼び出すことができる方法はありますか(parentActivity)?どのアクティビティがカスタムリストアダプタを呼び出しているかを知る方法は?
簡単な解決策は、すべてのリストのレイアウトを設計することですが、そのような冗長なコードは必要ありません。
customListAdapter:
public class CustomListAdapter extends BaseAdapter {
private final Context context;
private ArrayList<Product> products=new ArrayList<>() ;
public CustomListAdapter(Context context, ArrayList<Product> product) {
this.context=context;
this.products=product;
}
@Override
public int getCount() {
return products.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater=(LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView=inflater.inflate(R.layout.product_list_item, null, true);
TextView title = (TextView) rowView.findViewById(R.id.product_title);
//TextView url = (TextView) rowView.findViewById(R.id.product_url);
TextView createDate = (TextView) rowView.findViewById(R.id.product_create_date);
ImageView icon=(ImageView)rowView.findViewById(R.id.imageArrow);
...........
title.setText(productInfo.getTitle());
createDate.setText("Created Date: "+productInfo.getCreatedDate());
icon.setImageResource(R.drawable.go_right);
return rowView;
};
}
だから私は、履歴リストのための修正日付で作成された日付を変更したいです。
アダプタのコードを表示してください。 – Rohit5k2