How to use & access In android
First create object:-
WebAPIRequest web = new WebAPIRequest();
WebUrl weburl = new WebUrl();
Call Url and Execute :-
url = weburl .setURL() + "CompanyList";
new get_alert_activity().execute(url);
public class get_alert_activity extends AsyncTask<String, Void, Void> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
try {
} catch (Exception e) {
e.getMessage();
}
}
@Override
protected Void doInBackground(String... params) {
// TODO Auto-generated method stub
try {
response = web.performGet(params[0]);
Log.i("Response Display Extraactivity", response);
} catch (Exception e) {
e.getMessage();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
try {
Log.i("Test", response);
getjsontoListviewCompanyList(response);
datalistview dlv = new datalistview();
lv.setAdapter(dlv);
} catch (Exception e) {
e.getMessage();
}
}
}
public void getjsontoListviewCompanyList(String result) {
try {
jsonArray = new JSONArray(result);
for (i = 0; i <= jsonArray.length(); i += 1) {
list.add(jsonArray.getString(i));
lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list));
-------How to Use split Function and access String data-----------------------------------
JSONObject jobj;
jobj=new JSONObject(result);
String str1=jobj.getString("exam_get_questionsResult");
str2 = str1.split(";");
len=str2.length;
totallen=len;
Log.i("lengthofstring",String.valueOf( str2.length) );
newquestion = new String[len*6];
for(int i=0 ; i < str2.length;i++)
{
quetiondata = str2[i].split(",");
for(int k=0;k<6;k++)
{
newquestion[j]=quetiondata[k];
Log.i("Question",j + newquestion[j]);
j++;
}
}
-------End Split Function Code--------------------------------
}
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(getApplicationContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
Log.i("Result Response", e.getMessage());
}
}
public class datalistview extends BaseAdapter {
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Object getItem(int pos) {
// TODO Auto-generated method stub
return list.get(pos);
}
@Override
public long getItemId(int pos) {
// TODO Auto-generated method stub
return pos;
}
@Override
public View getView(int pos, View convertedView, ViewGroup viewgroup) {
// TODO Auto-generated method stub
LayoutInflater inflater = getLayoutInflater();
inflater = LayoutInflater.from(CompanyList.this);
convertedView = inflater.inflate(R.layout.list, null);
TextView tv = (TextView) convertedView
.findViewById(R.id.branch_name);
tv.setText(list.get(pos));
return convertedView;
}
}