With support, I have created a list of arrays that populates JSON data. When a user clicks on an item in the list of arrays, it takes them to an activity page that provides them more information about that particular item.
In particular, below are my 3 questions:
-
In the single item page, I added an "add more" button, and I would want that when the button is click, that particular item gets recorded until 3 different item in the list of arrays have been selected.
-
I would want to update the user of how many item have been selected thus far in a textview in the single item page.
-
I have added a confirm button, but I would want to set a condition, where it would only go to the next activity once 3 item have been selected.
-
Transmit the user recorded information to parse.com. Where every time, a user click on add more, it updates parse on the activity that have been selected by the user, where I could have three column for activity 1, activity 2, and activity 3 within my class.
Below is my list of arrays code:
public class EventsActivity extends Activity{
private static final String URL_WEB_SERVICE = "http://dooba.ca/analytics/ed.php";
private GridView gv;
private ArrayList<Events_List> container;
private ArrayList<Events_List> items;
public Uri list_item_bac;
public String list_item_name;
public String list_item_description;
public String single_list_item_description;
public String list_item_price;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.events_list_layout);
gv = (GridView) findViewById(R.id.gridview);
container = new ArrayList<Events_List>();
//download JSON
listDownload();
GridView s = (GridView) findViewById(R.id.gridview);
s.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(EventsActivity.this,EventSingleItemActivity.class);
intent.putExtra("list_item_name", container.get(position).getList_item_title());
intent.putExtra("single_list_item_description", container.get(position).getSingle_list_item_description());
startActivity(intent); //start Activity
}
});
}
public void listDownload(){
RequestQueue volley = Volley.newRequestQueue(this);
JsonObjectRequest json = new JsonObjectRequest(Method.GET, URL_WEB_SERVICE, null, ResponseListener(), ErrorListener());
volley.add(json);
}
private Response.Listener<JSONObject> ResponseListener() {
return new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
//your JSON Array
JSONArray array = response.getJSONArray("list_item");
for(int i = 0; i < array.length(); i++){
container.add(convertirAnuncio(array.getJSONObject(i)));
}
} catch (JSONException e) {
e.printStackTrace();
}
gv.setAdapter(new AdapterEvents(getApplicationContext(),container));
}
};
};
private Response.ErrorListener ErrorListener() {
return new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) { }
};
}
//object JSON
private final Events_List convertirAnuncio(JSONObject obj) throws JSONException {
long id = obj.getLong("id"); //id
String list_item_name = obj.getString("list_item_name");
String list_item_description = obj.getString("list_item_description");
String single_list_item_description = obj.getString("single_list_item_description");
Uri uri = Uri.parse(obj.getString("list_item_bac"));
return new Events_List(id,single_list_item_description,list_item_name,list_item_description,list_item_price, uri);
}
}
Below is my single item click page
public class EventSingleItemActivity extends Activity {
// Declare Variables
String list_item_name;
String list_item_description;
String list_item_price;
String single_list_item_description;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_events_single_item);
Intent i = getIntent();
list_item_name = i.getStringExtra("list_item_name");
single_list_item_description = i.getStringExtra("single_list_item_description");
TextView txtname = (TextView) findViewById(R.id.name);
TextView txtsdescription = (TextView) findViewById(R.id.sdescription);
// Set results to the TextViews
txtname.setText(list_item_name);
txtsdescription.setText(single_list_item_description);
Button mConfirm2 = (Button)findViewById(R.id.bConfirm2);
mConfirm2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EventSingleItemActivity.this.startActivity(new Intent(EventSingleItemActivity.this, MatchingActivity.class));
}
});
Button mcancel = (Button)findViewById(R.id.bRemove);
mcancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EventSingleItemActivity.this.startActivity(new Intent(EventSingleItemActivity.this, EventsActivity.class));
}
});
}
}
I have looked into the following tutorial:
http://theopentutorials.com/tutorials/android/listview/android-multiple-selection-listview/
but this is not exactly what I want to achieve.
Source: Android Layout Questions