I am implementing a listview which I already have it running, but I need to change the data that is displayed. In the table of the database that I show, I have 10 data with a foreign id, and 10 data with another foreign id, and so on, and what I want is to filter the data that is shown in the listview according to the foreign id that enter that in the application, this step is the one that I do not know how to implement it.
Here I leave the code of the listview and adapter, and screenshots of the app
public class ListarEstacionamientos extends AppCompatActivity{
JSONParser jsonParser = new JSONParser();
ListView listaestacionamiento;
private ProgressDialog progressDialog;
ProgressBar progressBar;
String idparkingholder;
private static final String REGISTER_URL ="http://www.app.transportessalgado.cl/listarcupos.php";
List<String > idLista=new ArrayList<>();
private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listar_estacionamientos);
listaestacionamiento = (ListView) findViewById(R.id.idlistview);
progressBar = (ProgressBar) findViewById(R.id.id_progressbar);
new GetHttpResponse(ListarEstacionamientos.this).execute();
idparkingholder=getIntent().getStringExtra("id_estacionamiento");
//new GetHttpResponse(ListarEstacionamientos.this).execute();
listaestacionamiento.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(ListarEstacionamientos.this, IngresoEstacionamientos.class);
// Sending ListView clicked value using intent.
intent.putExtra("valorLista", idLista.get(position).toString());
startActivity(intent);
//Finishing current activity after open next activity.
finish();
}
});
}
// JSON parse class started from here.
private class GetHttpResponse extends AsyncTask<Void, Void, Void>
{
public Context context;
String JSonResult;
List<Cupos> cuposList;
public GetHttpResponse(Context context)
{
this.context = context;
}
@Override
protected void onPreExecute()
{
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... arg0)
{
// Passing HTTP URL to HttpServicesClass Class.
HttpServicesClass httpServicesClass = new HttpServicesClass(REGISTER_URL);
try
{
httpServicesClass.ExecutePostRequest();
if(httpServicesClass.getResponseCode() == 200)
{
JSonResult = httpServicesClass.getResponse();
if(JSonResult != null)
{
JSONArray jsonArray = null;
try {
jsonArray = new JSONArray(JSonResult);
JSONObject jsonObject;
Cupos cupos;
cuposList = new ArrayList<Cupos>();
for(int i=0; i<jsonArray.length(); i++)
{
cupos = new Cupos();
jsonObject = jsonArray.getJSONObject(i);
// Adding Student Id TO IdList Array.
idLista.add(jsonObject.getString("id_cupo").toString());
//Adding Student Name.
cupos.cuposEstacionamiento = jsonObject.getString("id_cupo").toString();
cupos.estado=jsonObject.getString("estado").toString();
cuposList.add(cupos);
}
}
catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
else
{
Toast.makeText(context, httpServicesClass.getErrorMessage(), Toast.LENGTH_SHORT).show();
}
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result)
{
progressBar.setVisibility(View.GONE);
listaestacionamiento.setVisibility(View.VISIBLE);
ListAdapterClass adapter = new ListAdapterClass(cuposList, context);
listaestacionamiento.setAdapter(adapter);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menucerrarsesion, menu);
return true;
}
}
and here the adapter
public class ListAdapterClass extends BaseAdapter {
Context context;
List<Cupos> valueList;
public ListAdapterClass(List<Cupos> listValue, Context context)
{
this.context = context;
this.valueList = listValue;
}
@Override
public int getCount()
{
return this.valueList.size();
}
@Override
public Object getItem(int position)
{
return this.valueList.get(position);
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewItem viewItem = null;
if(convertView == null)
{
viewItem = new ViewItem();
LayoutInflater layoutInfiater = (LayoutInflater)this.context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = layoutInfiater.inflate(R.layout.vista_listview, null);
viewItem.TextViewCupos = (TextView)convertView.findViewById(R.id.txtcupos);
viewItem.estadoCupos=(TextView)convertView.findViewById(R.id.txtestados);
convertView.setTag(viewItem);
}
else
{
viewItem = (ViewItem) convertView.getTag();
}
viewItem.TextViewCupos.setText(valueList.get(position).cuposEstacionamiento);
viewItem.estadoCupos.setText(valueList.get(position).estado);
return convertView;
}
}
class ViewItem
{
TextView TextViewCupos;
TextView estadoCupos;
}
and here the screenshots of the application
Here I get the parking id and what I want is for me to show the data associated with that id in the listview. Any idea how to do it please.