Потяните, чтобы обновить Recyclerview AndroidAndroid

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

Сообщение Anonymous »

Привет, у меня активность вкладка, и на первой вкладке я извлекаю данные с сервера и показываю их в переработке в представлениях карт. Для получения данных с сервера я использую библиотеку Volley. Я хочу реализовать притяжение, чтобы обновить, чтобы загрузить данные (поэтому всякий раз, когда я притягиваю, это должно выполнять запрос в сеть). И я также хочу отключить сетевой запрос, когда я переключается между вкладками (потому что, когда я меняю вкладку фокусировку в моем приложении, он начинает получать данные), я хочу выполнить сетевой запрос только 1 время (когда пользователь входит в систему в первый раз), а затем Другие просят замолчать только путем обновления. < /p>

Вот мой фрагмент, где я перерабатываю и показываю данные: < /p>

public class Tab1History extends Fragment
{

private RecyclerView recyclerView;
private CespiteAdapter adapter;
UserSessionManager session;

private static final String URL_DATA = "http://mydata.php";

private List cespiteOggList;

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

View rootView = inflater.inflate(R.layout.tab1history, container, false);

recyclerView = (RecyclerView) rootView.findViewById(R.id.my_recycler_view);
recyclerView.setHasFixedSize(true);//every item of the RecyclerView has a fix size
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

cespiteOggList = new ArrayList();

loadRecyclerViewData();

return rootView;
}

private void loadRecyclerViewData()
{
// Session class instance
session = new UserSessionManager(getActivity());
//get user data from session
HashMap user = session.getUserDetails();
//get name
String name = user.get(UserSessionManager.KEY_NAME);
// get username
final String usernameUtente = user.get(UserSessionManager.KEY_USERNAME);

final ProgressDialog progressDialog = new ProgressDialog(getActivity());
progressDialog.setMessage("Carimento dati...");
progressDialog.show();

StringRequest stringRequest = new StringRequest(Request.Method.POST,
URL_DATA,
new Response.Listener() {
@Override
public void onResponse(String s) {
progressDialog.dismiss();
try {
JSONObject jsonObject = new JSONObject(s);
JSONArray array = jsonObject.getJSONArray("dates");

for(int i=0; i

и это адаптер: < /strong> < /p>

public class CespiteAdapter extends RecyclerView.Adapter
{

private List cespiteOggList;
private Context context;

public CespiteAdapter(List cespiteOggList, Context context) {

this.cespiteOggList = cespiteOggList;
this.context = context;
}

public class ViewHolder extends RecyclerView.ViewHolder
{

public CardView cv;
public TextView txtNumInventario;
public TextView txtNomeCespite;
public TextView txtDtCatalogazione;
public TextView txtAula;
public TextView txtNomeUser;

ViewHolder(View itemView)
{

super (itemView);
//cv = (CardView) itemView.findViewById(R.id.cardView);
txtNumInventario = (TextView) itemView.findViewById(R.id.txtNumeroInventario);
txtNomeCespite = (TextView) itemView.findViewById(R.id.txtNomeCespite);
txtDtCatalogazione = (TextView) itemView.findViewById(R.id.txtDataCatalogazione);
txtAula = (TextView) itemView.findViewById(R.id.txtAula);
txtNomeUser= (TextView) itemView.findViewById(R.id.txtNomeUser);

}
}

@Override
public CespiteAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{

LayoutInflater inflater = LayoutInflater.from(parent.getContext());

View cespiteView = inflater.inflate(R.layout.cespite_card_view, parent, false);

return new ViewHolder(cespiteView);
}

@Override
public void onBindViewHolder(ViewHolder holder, int position)
{

CespiteOgg cespiteOgg = cespiteOggList.get(position);

holder.txtNumInventario.setText(cespiteOgg.getNumInventario());
holder.txtNomeCespite.setText(cespiteOgg.getNomeCespite());
holder.txtDtCatalogazione.setText(cespiteOgg.getDtCatalogazione());
holder.txtAula.setText(cespiteOgg.getAula());
holder.txtNomeUser.setText(cespiteOgg.getNomeUser());

}

@Override
public int getItemCount()
{

return cespiteOggList.size();
}

}


Подробнее здесь: https://stackoverflow.com/questions/444 ... ew-android
Ответить

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

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

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

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

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