can not resolve symbol 'from' in
LayoutInflater inflater = new LayoutInflater.from(parent.getContext());
this is my complete class:
package ir.sangram.sangram.chat;
import android.content.Context;
import android.provider.ContactsContract;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import de.hdodenhof.circleimageview.CircleImageView;
import ir.sangram.sangram.R;
/**
* Created by HOW on 07/04/2017.
*/
class ChatListViewHolder extends RecyclerView.ViewHolder{
public CircleImageView profile_picture;
public TextView user_name, last_chat, unread_messages;
public ChatListViewHolder(View itemView) {
super(itemView);
profile_picture = (CircleImageView) itemView.findViewById(R.id.profile_picture);
user_name = (TextView) itemView.findViewById(R.id.user_name);
last_chat = (TextView) itemView.findViewById(R.id.last_chat);
unread_messages = (TextView) itemView.findViewById(R.id.unread_messages);
}
}
public class ChatListAdapter extends RecyclerView.Adapter<ChatListViewHolder>{
private List<ChatListData> chat_list = new ArrayList<ChatListData>();
public ChatListAdapter(List<ChatListData> chat_list) {
this.chat_list = chat_list;
}
@Override
public ChatListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = new LayoutInflater.from(parent.getContext());
//LayoutInflater inflater;// = new LayoutInflater.from(parent.getContext());
//inflater = ( LayoutInflater )parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);//!!!!!!!!!!
View itemView = inflater.inflate(R.layout.chat_list_row,parent,false);
return new ChatListViewHolder(itemView);
}
@Override
public void onBindViewHolder(ChatListViewHolder holder, int position) {
holder.profile_picture.setImageResource(chat_list.get(position).getProfile_picture_id());
holder.user_name.setText(chat_list.get(position).getUser_name());
holder.unread_messages.setText(chat_list.get(position).getUnread_messages());
holder.last_chat.setText(chat_list.get(position).getLast_chat());
}
@Override
public int getItemCount() {
return chat_list.size();
}
}
What can i do? please help me thnx
You're calling LayoutInflater.from
as if you were calling a constructor:
LayoutInflater inflater = new LayoutInflater.from(parent.getContext());
That's a mixture of constructor-call syntax (new
) and method call syntax (.from
). It would work if LayoutInflater.from
were a static nested class, but it's not... it's just at static method. So you want:
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
See more on this question at Stackoverflow