Pooveshin
Newbie
Hi All
In my Android App I am currently developing I have a page to show Historic/Archived data, The list view gets populated from the database with only the Name of school and Date. When a user clicks on a particular meeting a Dialog box displays and the option to only view is shown, when a user clicks view a second page opens and the data relating to that meeting shows.
Currently the app shows the meeting and name of school, when a user clicks the item the dialog opens up and a user can click view, My problem is when it goes to the next page to actually view the information no information comes up to be viewed.
If anyone can assist I have attached my code below.
Setting up the database table
CustomAdapter
List View to Show Headings and click
View to see all Data for specific meeting
In my Android App I am currently developing I have a page to show Historic/Archived data, The list view gets populated from the database with only the Name of school and Date. When a user clicks on a particular meeting a Dialog box displays and the option to only view is shown, when a user clicks view a second page opens and the data relating to that meeting shows.
Currently the app shows the meeting and name of school, when a user clicks the item the dialog opens up and a user can click view, My problem is when it goes to the next page to actually view the information no information comes up to be viewed.
If anyone can assist I have attached my code below.
Setting up the database table
Code:
public class UserMeetings extends Table {
public String table_name = "usermeetings";
public String primary_key = "id";
public String [] fillable_fields = new String [] {"name_of_school", "date", "venue", "meeting_notes"};
public Map<String, String> fields = new HashMap<>();
public String[] protected_fields = new String []{};
public UserMeetings()
{
super ("usermeetings", "id", new String []{"name_of_school", "date", "venue", "meeting_notes"}, new String []{}, new HashMap<String, String>());
}
public String getPrimary_key()
{
return primary_key;
}
public String getTable_name()
{
return table_name;
}
public String[] getFillable_fields()
{
return fillable_fields;
}
@Override
public Map<String, String> getFields()
{
return fields;
}
@Override
public void setFields(Map<String, String> fields)
{
this.fields = fields;
}
public String get_name()
{
if(!fields.get("name_of_school").isEmpty())
return fields.get("name_of_school");
return null;
}
public String get_field(String key)
{
if(fields.containsKey(key) && !fields.get(key).isEmpty())
return fields.get(key);
return "";
}
}
CustomAdapter
Code:
public class CustomUserMeetingsAdapter extends BaseAdapter {
public Context context;
private ArrayList<Map<String, String>> list;
private static LayoutInflater inflater = null;
private ListCallback callback;
public CustomUserMeetingsAdapter(Context mContext, ArrayList<Map<String, String>>list, ListCallback callback)
{
this.context = mContext;
this.list = list;
this.callback = callback;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount()
{
return list.size();
}
@Override
public Object getItem(int poisition)
{
return list.get(poisition);
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
View rowView;
Map<String, String> d = (Map<String, String>) getItem(position);
final int item = Integer.parseInt(d.get("id"));
Log.d("item in adapter", item + "");
final String name_of_school = d.get("name_of_school");
final String date = d.get("date");
rowView = inflater.inflate(R.layout.list_item, null);
TextView tv = (TextView) rowView.findViewById(R.id.txt_label);
tv.setText("Meeting : " + name_of_school + " "+ date);
rowView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setNegativeButton("View", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id)
{
callback.edit_process(item);
}
});
/*Map<String, String> where = new HashMap<>();
where.put("id", item + "");
DB db = GlobalHelper.getInstance().getDb();
db.delete_record((new UserMeetings()).getTable_name(), where);
callback.after_process();*/
AlertDialog dialog = builder.create();
dialog.show();
}
});
return rowView;
}
}
List View to Show Headings and click
Code:
public class UserArchivedData extends AppCompatActivity implements ListCallback{
GlobalHelper gh;
Context mContext;
TableHelper th;
DB db;
ListView lv_records;
ArrayList<Map<String, String>>data;
Button btn_create_meeting;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_archived_data);
gh = GlobalHelper.getInstance();
mContext = this;
lv_records = (ListView) findViewById(R.id.lv_records);
th = new TableHelper();
gh.setmContext(this);
db = gh.getDb();
data = new ArrayList<>();
btn_create_meeting = (Button) findViewById(R.id.btn_create_meeting);
btn_create_meeting.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
Intent i = new Intent(UserArchivedData.this, Capture_Meetings.class);
i.putExtra("create_process", 1);
startActivity(i);
}
}
);
Cursor cursor = db.get_data((new UserMeetings().getTable_name()));
if (cursor.moveToFirst())
{
while (cursor.isAfterLast()==false)
{
int index_meeting_id = cursor.getColumnIndex("id");
int index_name_of_school = cursor.getColumnIndex("name_of_school");
int id = cursor.getInt(index_meeting_id);
String name_of_school = cursor.getString(index_name_of_school);
Map<String, String> d = new HashMap<>();
d.put("id", id + "");
d.put("name_of_school", name_of_school);
data.add(d);
cursor.moveToNext();
}
}
cursor.close();
process_data();
}
@Override
public void after_process()
{
}
@Override
public void edit_process(int id)
{
}
private void process_data()
{
CustomUserMeetingsAdapter adapter = new CustomUserMeetingsAdapter(mContext, data, new ListCallback() {
@Override
public void after_process() {
data = new ArrayList<>();
Cursor cursor = db.get_data((new UserMeetings()).getTable_name());
if(cursor.moveToFirst())
{
while (cursor.isAfterLast() == false)
{
int index_meeting_id = cursor.getColumnIndex("id");
int index_name_of_school = cursor.getColumnIndex("name_of_school");
int id = cursor.getInt(index_meeting_id);
String name_of_school = cursor.getString(index_name_of_school);
Map<String, String> d = new HashMap<>();
d.put("id", id + "");
d.put("name_of_school", name_of_school);
data.add(d);
cursor.moveToNext();
}
}
cursor.close();
process_data();
}
@Override
public void edit_process(int id) {
Intent i = new Intent(UserArchivedData.this, ViewUserArchivedData.class);
i.putExtra("view", id);
startActivity(i);
}
});
lv_records.setAdapter(adapter);
}
}
View to see all Data for specific meeting
Code:
public class ViewUserArchivedData extends AppCompatActivity {
GlobalHelper gh;
DB db;
int id;
Cursor cursor;
UserMeetings name_of_school;
EditText editTextName;
EditText editDateTime;
EditText editVenue;
EditText editTextAddress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_user_archived_data);
gh = GlobalHelper.getInstance();
gh.setmContext(this);
db = gh.getDb();
Intent intent = getIntent();
id = intent.getIntExtra("View", -1);
Log.d("id","id" + id);
editTextName = (EditText)findViewById(R.id.editTextName);
editDateTime = (EditText) findViewById(R.id.editDateTime);
editVenue = (EditText) findViewById(R.id.editVenue);
editTextAddress = (EditText) findViewById(R.id.editTextAddress);
Map<String, String> where_data = new HashMap<>();
where_data.put("id",id + "");
cursor = db.get_data((new UserMeetings()).getTable_name(), where_data);
if (cursor.moveToFirst())
{
name_of_school = new UserMeetings();
while (cursor.isAfterLast() == false)
{
int index_id = cursor.getColumnIndex("id");
int index_name_of_school = cursor.getColumnIndex("name_of_school");
int index_date_time = cursor.getColumnIndex("date");
int index_venue = cursor.getColumnIndex("venue");
int index_address = cursor.getColumnIndex("meeting_notes");
int temp_id = cursor.getInt(index_id);
String str_school = cursor.getString(index_name_of_school);
String dateTime = cursor.getString(index_date_time);
String venue = cursor.getString(index_venue);
String meeting_notes = cursor.getString(index_address);
Map<String, String> d = new HashMap<>();
d.put("id", temp_id + "");
d.put("name_of_school", str_school);
d.put("date", dateTime);
d.put("venue", venue);
d.put("meeting_notes", meeting_notes);
name_of_school.setFields(d);
cursor.moveToNext();
}
}
cursor.close();
Log.d("school is","school is");
if (name_of_school != null)
{
Log.d("user is not null", "user is not null");
editTextName.setText(name_of_school.get_field("name_of_school"));
editDateTime.setText(name_of_school.get_field("date"));
editVenue.setText(name_of_school.get_field("venue"));
editTextAddress.setText(name_of_school.get_field("meeting_notes"));
}
else
{
Log.d("user is null", "user is null");
}
}
}

