last day (14 days later) » 

4:09 PM
0
A: In loopj how to get value to pass in the url of get request

K Neeraj LalInitialize the ListView (employeeList), datasource (employeeArray) and adapter (employeeAdapter) inside onCreate rather than doing it in onSuccess method. employeeList = (ListView) findViewById(R.id.list_employees); employeeArray = new ArrayList<Employee>(); employeeAdapter = new EmployeeAdapter...

 
@neeraj dont i need to pass value to "+age"? for example age = 25, so that it will list all the employees with age 25. in spinner i used onItemSelected to get the age value.
 
Could you give an example?
 
in onItemSelected i used position the get he value of age of the selected item and passed the value to url to get the desired result. like that here i want to list employee with certain age. in rest service my url is examplerestservice/employee/{age} in age i will give 25 and get the result. like that i have to pass value in client url to consume webservice and fetch the list
 
That is exactly what this does.
 
How will +age will get for example 25 ? sorry for my ignorance. please tell me
 
4:09 PM
If age is 25 then, "RestExample/employee/" + age will become => "RestExample/employee/25". Isn't this what you need?
 
Yes how will i pass 25 to age in place of +age? that is my problem. i have got getEmployees(long age) in oncreate method. here i want to pass age value. from there url will get it.
 
Where is your getEmployee method? The one shown in your code?
 
inside oncreate()
 
Can you show the whole class?
 
yes i will
 
4:11 PM
ok
 
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getEmployees();
}
i want to change this to getEmployees(long age)
 
Entire class
 
public class MainActivity extends ActionBarActivity {

private ListView employeeList;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getEmployees();
}
private void getEmployees() {
List<Header> headers = new ArrayList<Header>();
headers.add(new BasicHeader("Accept", "application/json"));

EmployeeRestClient.get(MainActivity.this, "RestExample/employee",
headers.toArray(new Header[headers.size()]),null,
new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
ArrayList<Employee> employeeArray = new ArrayList<Employee>();
EmployeeAdapter employeeAdapter = new EmployeeAdapter(MainActivity.this, employeeArray);
this code list all my employees with any issues.
 
So what is your issue now?
 
just i want to chacnge it to getEmployees(long age), so that i can list all empoyee with certain age
for that i dont know how to pass value
 
4:17 PM
Where do you get the age from?
 
that wt i dont know.
if get age there i can pass it
my restwebservice url is restexample/employees/{age}. so match that i have same url in client side
 
Figure it out
but for now,
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getEmployees(25);
}
private void getEmployees(Long age) {
List<Header> headers = new ArrayList<Header>();
headers.add(new BasicHeader("Accept", "application/json"));

EmployeeRestClient.get(MainActivity.this, "RestExample/employee/"+age,
headers.toArray(new Header[headers.size()]), null,
new JsonHttpResponseHandler() {

@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
for (int i = 0; i < response.length(); i++) {
try {
employeeArray.add(new Employee(response.getJSONObject(i)));
 
Try run this code
 
that i know
any suggestion please
its working
 
4:22 PM
no sugestions, these things depend on the requirement
*suggestions
 
in general how they do it
 
A spinner maybe
or an editext
or hardcoded
 
but i should list oncreate
 
if this solved your current issue, please accept the answer..... good luck
Post it as a different question maybe
 
ok i will do it. but my question was clear right? how to post again
are u there
 

last day (14 days later) »