私は、単にListViewにデータを表示するアプリケーションを作成しています。このデータは、アダプタを使用してListviewに追加する必要があります。 このアダプターでは、クリックしたときにリスト内の項目の重みを設定しようとしています。 ウェイトを1に設定して項目を展開しましたが、ウェイトを0に戻そうとしても何も起こりません。BaseAdapterクラスのAndroidセットのレイアウトの重さ
コードのこの部分では、レイアウトウェイトを1に設定しても動作しますが、0に戻す最初の部分は機能しません。
stat_item_container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.w("HiscoreAdapter","Stat item height "+gained_tracker_container.getHeight());
if(gained_tracker_container.getHeight() == 0){
gained_tracker_container.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,1));
}else{
Log.w("HiscoreAdapter","Setting stat item weight to 0");
gained_tracker_container.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,0));
}
}
});
ザ・アダプタクラス
public class HiscoreAdapter extends BaseAdapter {
private Context context;
private ArrayList<HiscoreItem> items;
public HiscoreAdapter(Context context, ArrayList<HiscoreItem> items){
this.context = context;
this.items = items;
}
@Override
public int getCount() {
return items.size();
}
@Override
public Object getItem(int position) {
return items.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.stats_item, parent, false);
final LinearLayout stat_item_container = (LinearLayout) row.findViewById(R.id.stat_item_container);
final LinearLayout gained_tracker_container = (LinearLayout) row.findViewById(R.id.gained_tracker_container);
TypedArray images = row.getResources().obtainTypedArray(R.array.skill_icons);
ImageView stats_icon = (ImageView) row.findViewById(R.id.stats_icon);
TextView rank_textview = (TextView) row.findViewById(R.id.rank_textview);
TextView level_textview = (TextView) row.findViewById(R.id.level_textview);
TextView exp_textview = (TextView) row.findViewById(R.id.exp_textview);
TextView daily_levels_textview = (TextView) row.findViewById(R.id.daily_levels_textview);
TextView weekly_levels_textview = (TextView) row.findViewById(R.id.weekly_levels_textview);
TextView monthly_levels_textview = (TextView) row.findViewById(R.id.monthly_levels_textview);
TextView daily_exp_textview = (TextView) row.findViewById(R.id.daily_exp_textview);
TextView weekly_exp_textview = (TextView) row.findViewById(R.id.weekly_exp_textview);
TextView monthly_exp_textview = (TextView) row.findViewById(R.id.monthly_exp_textview);
Picasso.with(row.getContext()).load("http://www.runescape.com/img/rsp777/hiscores/skill_icon_attack1.gif").into(stats_icon);
//stats_icon.setBackgroundResource(images.getResourceId(position, defaultValue));
rank_textview.setText(String.valueOf(items.get(position).getRank()));
level_textview.setText(String.valueOf(items.get(position).getLevel()));
exp_textview.setText(String.valueOf(items.get(position).getXp()));
daily_levels_textview.setText("+"+String.valueOf(items.get(position).getDayLevelGains())+" lvl");
weekly_levels_textview.setText("+"+String.valueOf(items.get(position).getWeekLevelGains())+" lvl");
monthly_levels_textview.setText("+"+String.valueOf(items.get(position).getMonthLevelGains())+" lvl");
daily_exp_textview.setText("+"+String.valueOf(items.get(position).getDayGains())+" exp");
weekly_exp_textview.setText("+"+String.valueOf(items.get(position).getWeekGains())+" exp");
monthly_exp_textview.setText("+"+String.valueOf(items.get(position).getMonthGains())+" exp");
stat_item_container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.w("HiscoreAdapter","Stat item height "+gained_tracker_container.getHeight());
if(gained_tracker_container.getHeight() == 0){
gained_tracker_container.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,1));
}else{
Log.w("HiscoreAdapter","Setting stat item weight to 0");
gained_tracker_container.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,0));
}
}
});
return row;
}
}
リストビューを更新したいのですか? –
@AminMemarianiあなたはそれが解決すると思いますか? –
はい私はそう思います! –