代码如下:
import android.content.Context;
import android.preference.Preference;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RatingBar;
import android.widget.TextView;
import com.tcad.marketassistant.R;
public class CommentsPreference extends Preference {
private LayoutInflater inflater;
private String rating;
private String author;
private String date;
private String content;
public CommentsPreference(Context context) {
super(context);
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
protected View onCreateView(ViewGroup parent) {
View v = inflater.inflate(R.layout.comments, null);
RatingBar r = (RatingBar)v.findViewById(R.id.com_rating);
TextView a = (TextView)v.findViewById(R.id.com_author);
TextView d = (TextView)v.findViewById(R.id.com_date);
TextView c = (TextView)v.findViewById(R.id.com_content);
if(rating!=null){
r.setRating(Float.parseFloat(rating));
}
if(author!=null){
a.setText(author);
}
if(date!=null){
d.setText(date);
}
if(content!=null){
c.setText(content);
}
return v;
}
public void setRaingAuthorDateContent(String rating,String author,String date,String content){
this.rating = rating;
this.author = author;
this.date = date;
this.content = content;
}
}
需要注意的是在onCreateView而不是onBindView中
分享到:
相关推荐
上篇博文代码实现了Android自带的preference组件,本文将通过实例讲解自定义preference组件。 主要通过以下几步来实现: 1.定义需要的layout布局res->layout->xml文件; 2.通过继承Preference类,来实现自定义...
android Preference自定义样式
Based on support-preference from Android Support Library, adding a lot of exciting features. Sample How to use add dependencies // replace with version above implementation 'moe.shizuku.preference...
Preference主要实现一些配置数据,一些我们上次点击选择的内容,我们希望在下次应用调起的时候依然有效,无须用户再一次进行配置或选择。Android提供preference这个键值对的方式来处理这种情况,自动保存这些数据,...
Preference组件是android的SharePreferences的衍生品,Preference组件的状态值是默认永久的保存在/data/data/包名/shared_prefs 目录下,因为Android系统的Setting应用及一些符合Android设计思想的应用的设置界面...
libgdx Preference
preference测试
android-support-v7-preference.jar
Laravel开发-preference Laravel的简单偏好包
Android Preference Framework源码~~~~~~~~~~~~~~~~~
Android中preference的使用,使用详解.
手把手教你设计像系统设置那样的操作界面,和用法
ViewPager实现滑动的Preference页面且带ActionBar
sRGB_v4_ICC_preference.icc
我们的app有时常需要包含Settings,那我们该怎样允许app使用Settings呢?这里我们就需要用到Preference类。
MyEclipse界面风格preference导出文件
Android中Preference的使用以及监听事件分析
Material Preference [Report an issue][1] This library can be used to implement Material Designed Settings/Preference Screen on Pre-Lollipop devices. (Currently supporting devices upto api 9 ) ...
安卓Android源码——Preference_Demo.rar
Constrained Preference Embedding for Item Recommendation