Since I schedule some time in C ++ and C # and now started a work in java 
android android studio. I have two small problems that I believe are easy 
to solve, the first is that I am getting data from a MySQL database using 
PHP, this bank there are 14 entries, my application is getting these 14 
entries, but repeating the last all Recycle List View, i.e the last value 
passed by JSON is repeated by the amount of select results. The other 
problem is that I am trying to use the Parcelable class to send data from a 
selected item in the recycle view the other activity, but without success, 
I think we have to create an array that stores these values during the Json 
as well the position of each item in the list but googled a lot and did not 
get success, your help will have great value to me! Below is my code. 
Thanks in advance.





























































































































































































































*Home Activity (my MainActivity):public class home_activity  extends 
AppCompatActivity    implements 
NavigationView.OnNavigationItemSelectedListener {private final String TAG = 
"home_activity";private List<product_lista> data = new 
ArrayList<>();private RecyclerView mRVConsulta;private AdapterConsulta 
mAdapter;private  ProgressDialog progress;@Overrideprotected void 
onCreate(Bundle savedInstanceState) {    
super.onCreate(savedInstanceState);    
setContentView(R.layout.home_layout);    Toolbar toolbar = (Toolbar) 
findViewById(R.id.toolbar);    setSupportActionBar(toolbar);    progress = 
new ProgressDialog(home_activity.this, R.style.AppTheme_Dark_Dialog);    
progress.setIndeterminate(true);    progress.setMessage("loading...");    
progress.show();    DrawerLayout drawer = (DrawerLayout) 
findViewById(R.id.drawer_layout);    ActionBarDrawerToggle toggle = new 
ActionBarDrawerToggle(            this, drawer, toolbar, 
R.string.navigation_drawer_open, R.string.navigation_drawer_close);    
drawer.setDrawerListener(toggle);    toggle.syncState();    NavigationView 
navigationView = (NavigationView) findViewById(R.id.nav_view);    
navigationView.setNavigationItemSelectedListener(this);    mRVConsulta = 
(RecyclerView) findViewById(R.id.mRVConsulta);    LinearLayoutManager 
layoutManager = new LinearLayoutManager(this);    
mRVConsulta.setLayoutManager(layoutManager);    data = new ArrayList<>();  
  mAdapter = new AdapterConsulta(data,this);    
mRVConsulta.setAdapter(mAdapter);    mRVConsulta.addItemDecoration(new 
DividerItemDecoration(home_activity.this, LinearLayoutManager.VERTICAL));  
  RequerimentServer();}@Overridepublic void onBackPressed() {    
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);    
if (drawer.isDrawerOpen(GravityCompat.START)) {        
drawer.closeDrawer(GravityCompat.START);    } else {        
super.onBackPressed();    }}@Overridepublic boolean 
onCreateOptionsMenu(Menu menu) {    // Inflate the menu; this adds items to 
the action bar if it is present.    getMenuInflater().inflate(R.menu.home, 
menu);    return true;}@Overridepublic boolean 
onOptionsItemSelected(MenuItem item) {    // Handle action bar item clicks 
here. The action bar will    // automatically handle clicks on the Home/Up 
button, so long    // as you specify a parent activity in 
AndroidManifest.xml.    int id = item.getItemId();    //noinspection 
SimplifiableIfStatement    if (id == R.id.action_settings) {        return 
true;    }    return 
super.onOptionsItemSelected(item);}@SuppressWarnings("StatementWithEmptyBody")@Overridepublic
 
boolean onNavigationItemSelected(MenuItem item) {    // Handle navigation 
view item clicks here.    int id = item.getItemId();    if (id == 
R.id.nav_historicoConsultas) {        // Handle the camera action    } else 
if (id == R.id.nav_wer) {    } else if (id == R.id.nav_wer2) {    } else if 
(id == R.id.nav_wer3) {    } else if (id == R.id.nav_wer4) {    } else if 
(id == R.id.nav_wer5) {    }    DrawerLayout drawer = (DrawerLayout) 
findViewById(R.id.drawer_layout);    
drawer.closeDrawer(GravityCompat.START);    return true;}private void 
RequerimentServer() {    String url = Config.URL_LISTA_PRODUCTS;    
Map<String, String> params2 = new HashMap<String, String>();    
params2.put(Config.KEY_ID, Config.idProduct);    CustomRequest jsObjRequest 
= new CustomRequest(Method.POST, url, params2, new 
Response.Listener<JSONObject>() {        @Override        public void 
onResponse(JSONObject response) {            Log.d("Response: >", 
response.toString() + "<");            JSONObject objeto = response;        
    JSONArray array = null;            try {                array = 
objeto.getJSONArray("result");            } catch (JSONException e) {      
          e.printStackTrace();            }            getData(array);      
  }    }, new Response.ErrorListener() {        @Override        public 
void onErrorResponse(VolleyError response) {            Log.d("Response: 
 >", response.toString() + "<");        }    });    RequestQueue 
requestQueue = Volley.newRequestQueue(home_activity.this);    
requestQueue.add(jsObjRequest);}protected void getData(JSONArray array) {  
  Log.d("Array adapter:  >", array.toString() + "<");            for(int i 
= 0; i<array.length(); i++)            {                product_lista lista 
= new product_lista();                JSONObject json_data = null;          
          try                    {                        json_data = 
array.getJSONObject(i);                        String dataEntrada = 
json_data.getString("data");                        SimpleDateFormat 
dataFormato = new SimpleDateFormat("dd/MM/yyyy");                        
Date convertedDate = new Date();                        try {              
              convertedDate = dataFormato.parse(dataEntrada);              
          } catch (ParseException e) {                            
e.printStackTrace();                        }                        String 
dataFinal = dataFormato.format(convertedDate);                        
lista.setdata(dataFinal);                        lista.setPreço 
(json_data.getString("preco"));                        if 
(json_data.isNull("detalhes"))                        {                    
        lista.setDetalhes ("Sem detalhes");                        } else  
                      {                            
lista.setDetalhes(json_data.getString("detalhes"));                        
}                        if (json_data.isNull("comentarios"))              
          {                            lista.setComentarios ( "Sem 
comentarios");                        }                        else        
                {                            lista.setComentarios 
(json_data.getString("comentarios"));                        }              
          lista.setProduto(json_data.getString("produto"));                
        lista.setProduto_id(json_data.getInt("pk_Produto"));                
    }                    catch (JSONException e)                    {      
                  e.printStackTrace();                    }                
mAdapter.notifyItemRangeChanged(0, mAdapter.getItemCount());                
data.add(lista);               }        progress.dismiss();}}*












































































































*Adapter:public class AdapterConsulta extends 
RecyclerView.Adapter<RecyclerView.ViewHolder> {private Context 
mContext;private List<product_lista> data;product_lista current;int 
currentPos = 0;private LayoutInflater inflater;public 
AdapterConsulta(List<product_lista> data, Context context){    super();    
this.mContext=context;    this.data=data;}private boolean 
isPositionItem(int position) {    return position != getItemCount() - 
1;}@Overridepublic RecyclerView.ViewHolder onCreateViewHolder(ViewGroup 
parent, int viewType) {    Context context = parent.getContext();    
LayoutInflater inflater = LayoutInflater.from(context);    View v = 
inflater.inflate(R.layout.container_consultas, parent, false);    return 
new MyHolder(v);}// Bind data@Overridepublic void 
onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {      
   final product_lista lista = data.get(position);        ((MyHolder) 
holder).textData.setText(lista.getdata());        ((MyHolder) 
holder).textProduct.setText(lista.getProduct());        ((MyHolder) 
holder).textPreco.setText(lista.getPreco());        ((MyHolder) 
holder).textData.setTextColor(ContextCompat.getColor(mContext, 
R.color.colorPrimaryDark));        if 
(lista.getComentarios().trim().equals("0")) {            ((MyHolder) 
holder).ivIcone.setImageResource(R.drawable.0);        } else {            
((MyHolder) holder).ivIcone.setImageResource(R.drawable.1);        
}}@Overridepublic int getItemCount() {    return data.size();} class 
MyHolder extends RecyclerView.ViewHolder implements OnClickListener {    
 TextView textData;     ImageView ivIcone;     TextView textPreco;    
 TextView textProduto;     public MyHolder(final View itemView) {        
 super(itemView);         itemView.setOnClickListener(this);        
 textData= (TextView) itemView.findViewById(R.id.textData);        
 textProduto= (TextView) itemView.findViewById(R.id.textProduto);        
 ivIcone= (ImageView) itemView.findViewById(R.id.ivConsulta);        
 textPreco = (TextView) itemView.findViewById(R.id.textPreco);     }    
 @Override     public void onClick(View v) {         Intent intent = new 
Intent(mContext, detalhes_consulta_activity.class);        
 intent.putExtra("EXTRA_DATA", consulta_lista.getdata());        
 intent.putExtra("EXTRA_PRECO, consulta_lista.getPreco());        
 intent.putExtra("EXTRA_DETALHES", consulta_lista.getDetalhes());        
 intent.putExtra("EXTRA_COMENTARIOS", consulta_lista.getComentarios());    
     intent.putExtra("EXTRA_PRODUTO", consulta_lista.getProduto());        
 intent.putExtra("EXTRA_ID", consulta_lista.getConsulta_id());        
 mContext.startActivity(intent);     } }}Digite o código aqui...Parceble 
Class*

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/9c922d4b-78cc-4c06-b032-411a5af4ef1f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to