Created
September 19, 2016 06:39
-
-
Save mdsami/cb9d03504b27b86f6da76daae05790dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.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; | |
@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(); | |
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); | |
} | |
//-- Onclick listen function | |
public void onListItemClick(ListView parent, View v, int position, long id) { | |
CheckedTextView item = (CheckedTextView) v; | |
Toast.makeText(this, shop[position] + " checked : " + | |
item.isChecked(), Toast.LENGTH_SHORT).show(); | |
} | |
// 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