두 개의 다른 어댑터에서 사용할 수 있어야하는 사용자 지정보기가 있습니다. 나는이 두 가지의 사용자 정의보기를 사용해야합니다, 지금여러 어댑터에서 사용자 지정보기 사용
public class CustomView extends RelativeLayout {
private final String TAG = "CustomView";
private User user;
private RelativeLayout container;
private ImageView imageView;
private TextView textView;
public CustomView(Context context) {
super(context);
init();
}
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CustomView(Context context, AttributeSet attrs, User user) {
super(context, attrs);
this.user = user;
init();
}
public CustomView(Context context, User user) {
super(context);
this.user = user;
init();
}
private void init() {
inflate(getContext(), R.layout.custom_view, this);
container = (RelativeLayout) findViewById(R.id.container);
avatar = (ImageView) findViewById(R.id.imaveView);
displayName = (TextView) findViewById(R.id.textView);
// Add the user profile picture to the imageView
Glide.with(getContext())
.load("http://www.website.com/img/users/" + user.getId() + "/avatar.png")
.into(imageView);
// Set the user username in the textView
textView.setText(user.getUsername());
}
}
: 여기
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/container">
<ImageView
android:id="@+id/imageView"
android:layout_height="100dp"
android:layout_width="100dp" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
사용자 정의보기의 클래스 (
CustomView.java
)입니다 : 여기
은 사용자 정의보기의 레이아웃 (
custom_view.xml
)입니다 어댑터.
나는 현재 다음과 같습니다 일반 RecyclerView
어댑터입니다에서 사용자 지정보기를 사용할 필요가 첫 번째 어댑터 :이 클래스의 사용자 정의보기를 부풀려 수 있고 내가 어떻게 결합 할 수있는 방법
public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder> {
private static final String TAG = "CustomAdapter";
private Context context;
private List<User> userData;
public CustomAdapter(Context context, List<User> userData) {
this.context = context;
this.userData = userData;
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ViewHolder(View v) {
super(v);
}
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// TODO: WHAT DO I PUT HERE?
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
// TODO: WHAT DO I PUT HERE?
}
@Override
public int getItemCount() {
return userData.size();
}
}
그것에 userData
?
사용자 정의보기를 사용해야하는 두 번째 어댑터는 AndroidTreeView library의 어댑터입니다. 여기, 참고로
public class CustomTreeAdapter extends TreeNode.BaseNodeViewHolder<CustomTreeAdapter.TreeItem> {
public CustomTreeAdapter(Context context) {
super(context);
}
@Override
public View createNodeView(TreeNode node, TreeItem value) {
// TODO: WHAT DO I PUT HERE?
}
public static class TreeItem {
// TODO: WHAT DO I PUT HERE?
}
}
AndroidTreeView 라이브러리에 대한 integration documentation입니다 :
다음은 AndroidTreeView 라이브러리 내 어댑터 (지금까지)입니다.
위의 방법으로 무엇을 넣어야합니까?
감사합니다.
RecyclerView를 들어
이미 사용자 정의 뷰 클래스에 모든 textview 텍스트를 설정 했으므로 ViewHolder에서'setText()'를 다시 수행하는 것은 의미가 없습니다. – l890456
그러나 ViewHolder는 항목/행에 대한보기를 설정해야한다고 생각했습니다. –
'setText()'를 두 번 (각 어댑터에서 한번)하는 것은 사용자 정의 뷰 클래스에서 한 번 할 수 있다면 이해가되지 않습니다. – l890456