Skip to content

Instantly share code, notes, and snippets.

@mdsami
Last active September 19, 2016 08:52
Show Gist options
  • Save mdsami/7740d1ea418a27a050c30c57dbf5cfb0 to your computer and use it in GitHub Desktop.
Save mdsami/7740d1ea418a27a050c30c57dbf5cfb0 to your computer and use it in GitHub Desktop.
package com.atomapgroup.aeonshopping;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckedTextView;
import android.widget.ListView;
import android.widget.Toast;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import java.io.IOException;
/**
* Created by mdsami on 9/2/16.
*
*/
public class SelectStore extends AppCompatActivity {
//-- Shop list for the preview
String[] shop = {
"AEON AU2 (Setiawangsa)",
};
ListView listView;
int counter = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.selectstore);
listView = (ListView) findViewById(android.R.id.list);
// -- Display mode of the ListView
listView.setChoiceMode(listView.CHOICE_MODE_MULTIPLE);
//-- text filtering
listView.setTextFilterEnabled(true);
//-- Send request to the server and generate view
sendRequest();
//-- Onclick listen function
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
CheckedTextView item = (CheckedTextView) view;
Toast.makeText(SelectStore.this, shop[position] + " checked : " +
item.isChecked(), Toast.LENGTH_SHORT).show();
}
});
Button Save = (Button) findViewById(R.id.save);
Save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(SelectStore.this, NavigationActivity.class));
}
});
//-- Set Custom icon in ActionBar
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.actionbar);
}
// Send request to the server and return the list
private void sendRequest() {
// -- Load data from database
StringRequest stringRequest = null;
try {
stringRequest = new StringRequest(Utilities.getProperty("json.storelist", getApplicationContext()),
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
ParseStoreJSON pj = new ParseStoreJSON(response);
pj.parseJSON();
//ParseStoreJSON.ids;
shop = new String[ParseStoreJSON.names.length];
shop = ParseStoreJSON.names;
listView.setAdapter(new ArrayAdapter<String>(SelectStore.this,
android.R.layout.simple_list_item_checked, shop));
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(SelectStore.this, error.getMessage(), Toast.LENGTH_LONG).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment