Как добавить представление переработчика во фрагментAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Как добавить представление переработчика во фрагмент

Сообщение Anonymous »

Я пробовал много способов добавить recyclerview внутрь фрагмента. Я новичок в андроиде. В моем Android есть 5 фрагментов, один из которых мне нужно добавить в recyclerview. вот мой код

notification_item.xml
notification_Fragment.xml
NotificationItem.java

Код: Выделить всё

public class NotificationItem {
private String title;
private int imageResId;

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public int getImageResId() {
return imageResId;
}

public void setImageResId(int imageResId) {
this.imageResId = imageResId;
}
}
NotificationData.java

Код: Выделить всё

public class NotificationData {
private static final String[] textItem = {"pathum", "sai", "charu"};
private static final int[] imgItem = {android.R.drawable.ic_popup_reminder, android.R.drawable.ic_menu_add, android.R.drawable.ic_menu_delete};

public static List getListData() {
List data = new ArrayList();

for (int x = 0; x < 4; x++) {
for (int i = 0; i < textItem.length && i < imgItem.length; i++) {
NotificationItem item = new NotificationItem();
item.setImageResId(imgItem[i]);
item.setTitle(textItem[i]);
data.add(item);
}
}

return data;
}

}
NotificationAdapter.java

Код: Выделить всё

public class NotificationAdapter extends RecyclerView.Adapter {

private List listData;
private LayoutInflater inflater;

public NotificationAdapter(List  listData, Context c) {

this.inflater = LayoutInflater.from(c);
this.listData = listData;
}

@Override
public NotificationHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.notification_item,parent,false);
return new NotificationHolder(view);
}

@Override
public void onBindViewHolder(NotificationHolder holder, int position) {
NotificationItem item = listData.get(position);
holder.title.setText(item.getTitle());
holder.icon.setImageResource(item.getImageResId());
}

@Override
public int getItemCount() {
return listData.size();
}

class NotificationHolder extends RecyclerView.ViewHolder {

private TextView title;
private CircleImageView icon;
private View container;

public NotificationHolder(View itemView) {
super(itemView);

title = (TextView) itemView.findViewById(R.id.notification_item_text);
icon = (CircleImageView) itemView.findViewById(R.id.notification_item_img);
container = itemView.findViewById(R.id.notification_item_root);
}
}
}
NotificationFragment.java

Код: Выделить всё

public class NotificationFragment extends Fragment {

RecyclerView recyclerView;
NotificationAdapter notificationAdapter;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.notification_fragment, container, false);
recyclerView = (RecyclerView) rootView.findViewById(R.id.notification_list);

recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

notificationAdapter = new NotificationAdapter(NotificationData.getListData(),this);
recyclerView.setAdapter(notificationAdapter);

return rootView;
}
}

Мне не удалось сделать это правильно в NotificationFragment.java и NotificationAdapter.java, пожалуйста, помогите мне, ребята.

Подробнее здесь: https://stackoverflow.com/questions/418 ... o-fragment
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»