Permalink
Browse files

list view editing

  • Loading branch information...
1 parent a157c5e commit cc01d3e406a46713a6d783fd20fc94b0d5cd73a1 @mahmoud-abdelaziz committed Apr 6, 2013
@@ -20,8 +20,7 @@
public static final int ic_launcher=0x7f020000;
}
public static final class id {
- public static final int button1=0x7f080027;
- public static final int create_event=0x7f08002f;
+ public static final int create_event=0x7f080030;
public static final int event_create_btn=0x7f08001c;
public static final int event_create_building=0x7f080012;
public static final int event_create_date=0x7f080016;
@@ -31,13 +30,14 @@
public static final int event_create_room=0x7f080014;
public static final int event_create_space=0x7f080011;
public static final int event_create_time=0x7f080017;
- public static final int event_view_date=0x7f080025;
- public static final int event_view_desc=0x7f080026;
- public static final int event_view_name=0x7f080024;
+ public static final int event_view_date=0x7f080026;
+ public static final int event_view_desc=0x7f080027;
+ public static final int event_view_name=0x7f080025;
public static final int imageView1=0x7f08001d;
public static final int item_event_attending=0x7f080020;
public static final int item_event_date=0x7f08001f;
public static final int item_event_edit=0x7f080021;
+ public static final int item_event_id=0x7f080024;
public static final int item_event_mark_past=0x7f080022;
public static final int item_event_name=0x7f08001e;
public static final int item_event_remove=0x7f080023;
@@ -46,22 +46,23 @@
public static final int login_password=0x7f080002;
public static final int login_register_btn=0x7f080004;
public static final int login_remember_me=0x7f080003;
- public static final int menu_settings=0x7f08002e;
+ public static final int menu_settings=0x7f08002f;
public static final int my_events=0x7f08000e;
- public static final int radio0=0x7f08002b;
- public static final int radio1=0x7f08002c;
- public static final int radio2=0x7f08002a;
- public static final int radioGroup1=0x7f080029;
+ public static final int radio0=0x7f08002c;
+ public static final int radio1=0x7f08002d;
+ public static final int radio2=0x7f08002b;
+ public static final int radioGroup1=0x7f08002a;
public static final int register_course=0x7f08000c;
public static final int register_finish=0x7f08000d;
public static final int register_year=0x7f08000a;
public static final int regsiter_email=0x7f080006;
public static final int regsiter_password=0x7f080007;
public static final int regsiter_re_password=0x7f080008;
public static final int scrollView1=0x7f08000f;
- public static final int search_btn=0x7f08002d;
- public static final int search_event=0x7f080030;
- public static final int search_name=0x7f080028;
+ public static final int search_btn=0x7f08002e;
+ public static final int search_event=0x7f080031;
+ public static final int search_name=0x7f080029;
+ public static final int sign_up=0x7f080028;
public static final int textView1=0x7f080000;
public static final int textView2=0x7f080009;
public static final int textView3=0x7f08000b;
@@ -63,6 +63,14 @@
</LinearLayout>
+ <TextView
+ android:id="@+id/item_event_id"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Small Text"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:visibility="visible" />
+
</LinearLayout>
</LinearLayout>
@@ -58,7 +58,7 @@
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
- android:id="@+id/button1"
+ android:id="@+id/sign_up"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign up" />
@@ -8,6 +8,7 @@
public EventsArrayAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
// TODO Auto-generated constructor stub
+
}
}
@@ -6,38 +6,48 @@
import java.util.Map;
import android.content.Context;
+import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.SimpleAdapter;
+import android.widget.TextView;
public class EventsItem extends SimpleAdapter implements OnClickListener {
private ArrayList<HashMap<String, String>> list;
- int pos=0;
+ int pos = 0;
String name = "";
-
+ Context myContext;
public EventsItem(Context context,
ArrayList<HashMap<String, String>> eventsList, int resource,
String[] from, int[] to) {
+
super(context, eventsList, resource, from, to);
+ myContext = context;
this.list = eventsList;
pos = this.getCount();
- Log.d("Edit", pos+"");
+ Log.d("Edit", pos + "");
+
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
- Button edit = (Button) view.findViewById(R.id.item_event_edit);
- edit.setOnClickListener(this);
+ view.setOnClickListener(this);
return view;
}
@Override
- public void onClick(View v) {
-// Log.d("Edit", pos + "");
+ public void onClick(View view) {
+ TextView tv = (TextView) view.findViewById(R.id.item_event_id);
+ name = tv.getText().toString();
+ Intent i = new Intent(myContext,
+ ReadEventActivity.class);
+ i.putExtra("id", name);
+ myContext.startActivity(i);
+ Log.d("data", name);
}
@@ -21,15 +21,16 @@
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
-import android.widget.SimpleAdapter;
+import android.view.View;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.*;
public class MyEventsActivity extends ListActivity {
String token;
ArrayList<HashMap<String, String>> eventsList;
- String Qtype,query ;
+ String Qtype, query;
+
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
eventsList = new ArrayList<HashMap<String, String>>();
@@ -44,18 +45,17 @@ protected void onCreate(Bundle savedInstanceState) {
// if(type == -1 )
Qtype = intent.getStringExtra("type");
query = intent.getStringExtra("query");
-// new LoginTask().execute(intent.getStringExtra("type"),
-// intent.getStringExtra("query"));
+
}
@Override
protected void onResume() {
MyEventsActivity.this.setListAdapter(null);
- new LoginTask().execute(Qtype,
- query);
+ new LoginTask().execute(Qtype, query);
Log.d("data", "OnResume");
super.onResume();
}
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
@@ -83,7 +83,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
- final String LOGIN_URL = URLs.url+"/events.php";
+ final String LOGIN_URL = URLs.url + "/events.php";
class LoginTask extends AsyncTask<String, String, String> {
boolean login = false;
@@ -98,7 +98,7 @@ protected void onPreExecute() {
pDialog.show();
eventsList.clear();
}
-
+
@Override
protected String doInBackground(String... args) {
@@ -109,14 +109,16 @@ protected String doInBackground(String... args) {
Log.d("MYTOKEN", token);
JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "GET",
params);
+ Log.d("url", params.toString());
Log.d("json", json.toString());
try {
JSONArray events = json.getJSONArray("events");
for (int i = 0; i < events.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject event = events.getJSONObject(i);
map.put("name", event.getString("name"));
- Log.d("data", event.getString("name"));
+ map.put("id", event.getString("id"));
+// Log.d("data", event.getString("name"));
// the rest goes here
eventsList.add(map);
@@ -128,12 +130,13 @@ protected String doInBackground(String... args) {
}
protected void onPostExecute(String file_url) {
-
+
MyEventsActivity.this
.setListAdapter(new EventsItem(MyEventsActivity.this,
eventsList, R.layout.event_item,
- new String[] { "name" },
- new int[] { R.id.item_event_name }));
+ new String[] { "name", "id" },
+ new int[] { R.id.item_event_name, R.id.item_event_id }));
+//
pDialog.dismiss();
}
@@ -15,21 +15,37 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
import android.widget.TextView;
public class ReadEventActivity extends Activity {
+ String token;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.event_view);
- new LoginTask().execute();
+ SharedPreferences settings = getSharedPreferences("main", 0);
+ token = settings.getString("token", "noLogged");
+ final String eventId = getIntent().getStringExtra("id");
+ Button signup = (Button)findViewById(R.id.sign_up);
+ signup.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new LoginTask().execute("join", eventId);
+ }
+ });
+ new LoginTask().execute("read", eventId);
}
ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
- final String LOGIN_URL = URLs.url+"/events.php";
- String name, date, descioption ;
+ final String LOGIN_URL = URLs.url + "/events.php";
+ String name, date, descioption;
+
class LoginTask extends AsyncTask<String, String, String> {
boolean login = false;
@@ -53,10 +69,9 @@ protected String doInBackground(String... args) {
// String emailStr = email.getText().toString();
// String passwordStr = password.getText().toString();
List<NameValuePair> params = new ArrayList<NameValuePair>();
- params.add(new BasicNameValuePair("type", "read"));
- params.add(new BasicNameValuePair("id", "2"));
- params.add(new BasicNameValuePair("token",
- "4167d27aebe5b9cb0e6b765563f85876"));
+ params.add(new BasicNameValuePair("type", args[0]));
+ params.add(new BasicNameValuePair("id", args[1]));
+ params.add(new BasicNameValuePair("token", token));
// params.add(new BasicNameValuePair("password", passwordStr));
JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "GET",
@@ -69,7 +84,8 @@ protected String doInBackground(String... args) {
} else {
name = json.getJSONObject("event").getString("name");
date = json.getJSONObject("event").getString("date_time");
- descioption = json.getJSONObject("event").getString("description");
+ descioption = json.getJSONObject("event").getString(
+ "description");
}
} catch (Exception e) {
// TODO Auto-generated catch block
@@ -85,13 +101,16 @@ protected String doInBackground(String... args) {
protected void onPostExecute(String file_url) {
// dismiss the dialog once done
pDialog.dismiss();
- TextView nameView= (TextView)ReadEventActivity.this.findViewById(R.id.event_view_name);
- TextView dateView= (TextView)ReadEventActivity.this.findViewById(R.id.event_view_date);
- TextView descView= (TextView)ReadEventActivity.this.findViewById(R.id.event_view_desc);
-
- nameView.append( ":" + name);
- nameView.append( ":" + date);
- nameView.setText(descioption);
+ TextView nameView = (TextView) ReadEventActivity.this
+ .findViewById(R.id.event_view_name);
+ TextView dateView = (TextView) ReadEventActivity.this
+ .findViewById(R.id.event_view_date);
+ TextView descView = (TextView) ReadEventActivity.this
+ .findViewById(R.id.event_view_desc);
+
+ nameView.setText( name);
+ dateView.setText( date);
+ descView.setText(descioption);
}
}

0 comments on commit cc01d3e

Please sign in to comment.