I have a problem with my looping.
this is my function class in my java, and i want to view the data from this function
class appointment extends AsyncTask<String, String, String>
{
private String val3;
public appointment(String medicalno) {
this.val3 = medicalno;
}
@Override
protected String doInBackground(String... strings) {
CallSoap cs = new CallSoap();
String medno = cs.InfoUser(val3);
String[] temp = medno.split(",");
String data = cs.HistoryTomorrow(temp[0]);
return data;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
//Toast.makeText(Appointment.this,s.toString(),Toast.LENGTH_SHORT).show();
poli.clear();
nama.clear();
tanggal.clear();
if(s.equals("No Data"))
{
poli.add("");
nama.add(s);
tanggal.add("");
}
else {
String data = s.replaceAll("[a-zA-Z0-9/:#., ]*","");
if(data.length()<1)
{
String data2[] = s.split("#");
poli.add(data2[0]);
nama.add(data2[1]);
tanggal.add(data2[2]);
}
else {
String data1[] = s.split("%");
Toast.makeText(Appointment.this,data,Toast.LENGTH_SHORT).show();
for (int i = 0; i < data.length()+1; i++) {
poli.add(data1[i] + "_____"+i);
nama.add("");
tanggal.add("");
}
}
}
list.setAdapter(new HistoryTodayTomorrowAdapter(Appointment.this, poli,nama,tanggal));
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(Appointment.this,poli.get(position),Toast.LENGTH_SHORT).show();
}
});
}
}
this is my HistoryTodayTomorrowAdapter
package info.androidhive.Adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.ArrayList;
import info.androidhive.recyclerviewsearch.R;
public class HistoryTodayTomorrowAdapter extends BaseAdapter {
private Context context;
private final ArrayList<String> Poli,Nama,Tanggal;
public HistoryTodayTomorrowAdapter(Context context, ArrayList<String> poli,ArrayList<String> nama,ArrayList<String> tanggal) {
this.context = context;
this.Poli = poli;
this.Nama = nama;
this.Tanggal = tanggal;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;
if (convertView == null) {
gridView = new View(context);
// get layout from mobile.xml
gridView = inflater.inflate(R.layout.user_row_appoint, null);
// set value into textview
TextView textView = (TextView) gridView.findViewById(R.id.NamaPoli);
TextView textView1 = (TextView) gridView.findViewById(R.id.Tanggal);
TextView textView2 = (TextView) gridView.findViewById(R.id.Nama);
textView.setText(Nama.get(position));
textView1.setText(Poli.get(position));
textView2.setText(Tanggal.get(position));
} else {
gridView = (View) convertView;
}
return gridView;
}
@Override
public int getCount() {
return Poli.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
}
and this is my return data from HistoryTomorrow
(Example)
data1#qwe1#a123%data2#qwe2#b123%data3#qwe3#c123%data4#qwe4#d123%data5#qwe5#e123
but i get the view data like this(Contact List):
data1 - qwe1 - a123
data2 - qwe2 - b123
data3 - qwe3 - c123
data1 - qwe1 - a123
data2 - qwe2 - b123
The code will looping right 5 times like 5 data in the row. but the data view is not right. it just looping for the 3 data not 5/all data.