You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.8 KiB
69 lines
1.8 KiB
package com.community.pocket.data.adapter;
|
|
|
|
import android.os.Build;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.BaseAdapter;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
|
import com.community.pocket.util.LocaleType;
|
|
|
|
import org.xutils.view.annotation.ViewInject;
|
|
import org.xutils.x;
|
|
|
|
/**
|
|
* 切换语言数据适配器
|
|
*/
|
|
public class LocaleAdapter extends BaseAdapter {
|
|
private LayoutInflater inflater;
|
|
|
|
public LocaleAdapter(LayoutInflater inflater) {
|
|
this.inflater = inflater;
|
|
}
|
|
|
|
@Override
|
|
public int getCount() {
|
|
return LocaleType.values().length;
|
|
}
|
|
|
|
@Override
|
|
public Object getItem(int position) {
|
|
return LocaleType.getLocale(position);
|
|
}
|
|
|
|
@Override
|
|
public long getItemId(int position) {
|
|
return position;
|
|
}
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
|
|
@Override
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
|
ViewHolder viewHolder;
|
|
if (convertView == null) {
|
|
convertView = inflater.inflate(android.R.layout.simple_list_item_1, null);
|
|
viewHolder = new ViewHolder();
|
|
//ViewHolder注解
|
|
x.view().inject(viewHolder, convertView);
|
|
convertView.setTag(viewHolder);
|
|
} else {
|
|
viewHolder = (ViewHolder) convertView.getTag();
|
|
}
|
|
|
|
String text = convertView.getContext().getString(LocaleType.getLocale(position).getResId());
|
|
viewHolder.childName.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
|
viewHolder.childName.setText(text);
|
|
return convertView;
|
|
}
|
|
|
|
|
|
protected static class ViewHolder {
|
|
@ViewInject(android.R.id.text1)//加载item的控件
|
|
TextView childName;
|
|
}
|
|
|
|
|
|
}
|
|
|