i have a list of object in an activity in which a button in the same activity adds an object to it on every click
i want to be capable to access that list and iterate it from any other activity
i made it public but it gave me an error !
package com.fawzyx.movie_rental_store;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MovieReg_activity extends Activity {
public List<movie> movies = new ArrayList<movie>();
String movName ;
int dvdNo ;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mov_reg_layout);
EditText etmovie_name = (EditText)findViewById(R.id.etmovname);
EditText etdvd_no = (EditText)findViewById(R.id.etdvds);
Button btMovie_submit = (Button)findViewById(R.id.btmovsubmit);
movName= etmovie_name.getText().toString();
dvdNo = Integer.parseInt(etdvd_no.getText().toString()); // to string then to int :)
btMovie_submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
movies.add(new movie(movName , dvdNo) );
Toast.makeText(MovieReg_activity.this, "Movie Added", Toast.LENGTH_LONG).show();
}
});
}
}
is there a way to access and iterate the list movies from any other activity ?
You can use a static way to access to this list :
public static List<movie> movies = new ArrayList<movie>();
Then from the other activity :
int size = MovieReg_activity.movies.size(); // exp: check the size
for(movie m : MovieReg_activity.movies){
// do something with m
}
if you want to make a global list, create a static variable or put it in your application class and access it via context.
Search about creating a custom application class.
Maybe use a singleton class that holds your movie list.
Then you'll be able to access it everywhere.
http://androidresearch.wordpress.com/2012/03/22/defining-global-variables-in-android/
Related
I created a ListDialog extending a DialogFragment class and I have a problem with understanding of this code in the DijalogX class
((MainActivity)getActivity()).setTextField(selectedItem);
I understand that with this code above I put selected String variable to the setTextField method as an argument and after that this variable is showed in TextView on MainActivity class.
My questions:
Why I need a cast from getActivity() to the MainActivity and how I get access from DijalogX(fragment) to the method setTextField in MainActivity? Please explain a little about this process.
I also tried instead of ((MainActivity)getActivity()).setTextField(selectedItem)
use an Interface and everything works nice and I got the same resoult but I am wondering what is better solution here Interface or ((MainActivity)getActivity()).setTextField(selectedItem)?
MainActivity
package com.example.dezox.dijaloglist;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity{
private Button btnStartDialog;
private TextView tvSelectedOption;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initWidgets();
setupListener();
}
private void initWidgets() {
btnStartDialog = findViewById(R.id.btnDialog);
tvSelectedOption = findViewById(R.id.tvselectedOption);
}
private void setupListener() {
btnStartDialog.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DijalogX dijalogX = new DijalogX();
dijalogX.show(getSupportFragmentManager(), "dx");
tvSelectedOption.setText("");
}
});
}
public void setTextField(String odabrano){
tvSelectedOption.setText(odabrano);
}
public String getTextField(){
return tvSelectedOption.getText().toString();
}
}
DijalogX
package com.example.dezox.dijaloglist;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
public class DijalogX extends DialogFragment {
private String[] languageList;
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initListResource();
}
private void initListResource() {
languageList = getResources().getStringArray(R.array.language_list);
}
#NonNull
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(),
android.R.style.Theme_Material_Dialog_Alert)
.setTitle("Select Language: ")
.setItems(languageList, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
String selectedItem = languageList[which];
//THIS PART OF THE CODE I DONT UNDERSTAND:
((MainActivity)getActivity()).setTextField(selectedItem);
}
});
return builder.create();
}
}
You have declared a method in MainActivity called setTextField. If you called
Activity a = getActivity();
you would not be able to call your custom method (it is on your derived class, not the base Activity class).
a.setTextField(selectedIte); // WON'T WORK - NO SUCH METHOD
If instead you call
MainActivity ma = (MainActivity)getActivity();
it is now cast as your derived class and you can then call
ma.setTextField(selectedItem);
Doing it in two lines like this is the same as calling the one-liner in your code
((MainActivity)getActivity()).setTextField(selectedItem);
As far as casting vs. an interface, an interface is a bit more flexible of an approach. If you tried to use this fragment in a different activity (not MainActivity) the casting approach would fail. If you are only ever going to use the fragment in this Activity then either would work.
I have 3 classes: LoginActivity,MapsActivity and MatchAdapter
The first 2 extends AppCompactActivity, the last one ArrayAdapter.
When i make login (if correct, matching on mySQLiteDB) i used to get ID_contact of current user and pass it to MapsActivity with intent in such way:
On my LoginActivity:
String contact=databaseHelper.searchID_Contact(username,password);
Intent intent=new Intent(LoginActivity.this,MapsActivity.class);
intent.putExtra("ID_CONTACT",contact);
startActivity(intent);
On MapsActivity i can easily retrieve this data in such way:
public String getId_contact(String conct){
return conct;
}
#Override
public void onMapReady(GoogleMap googleMap) {
String id_contact1=getIntent().getStringExtra("ID_CONTACT");
String contact=getId_contact(id_contact1);
Toast.makeText(MapsActivity.this, contact, Toast.LENGTH_LONG).show();
}
Till now everything works fine, it appears the id of the current user.
My problem is to pass this data (with intent i don't know how) even to another class named MatchAdapter that extends ArrayAdapter.
I tried this way on MapsActivity:
public class MapsActivity extends AppCompatActivity implements ...{
public String getId_contact(){
String contact=getIntent().getStringExtra("ID_CONTACT");
return contact;
}
So on MatchAdaper trying to retrieve such way:
MapsActivity mapsActivity=new MapsActivity();
String text=mapsActivity.getId_contact().toString();
But nothing..i get NULLPOINTEREXCEPTION...Can someone help me?
Ok...found the solution...On MatchAdapter extends ArrayAdapter
DatabaseHelper databaseHelper=new DatabaseHelper(getContext());
...than OnClick function....
databaseHelper.myfunction();
Well you can access method of activity from an adapter by following way, Call this method from constructor of adapter or anywhere you want.
((ActivityName)context).methodName();
When you create a new instance of MapsActivity, that isn't the same Activity instance you got when you called startActivity(). This is basically why you have a null pointer exception.
More importantly, you should never be manually creating Activity instances using "new". Generally the system creates Activity objects for you via mechanisms like startActivity(), and that is how you should obtain them.
Himanshu's suggestion can work, if your activity does happen to be "hosting" your adapter, but this isn't always guaranteed. A better approach is to pass the ID to your MatchAdapter directly, either in the constructor or as a direct setter function. At the least, you should perform a "instanceof" check to make sure your adapter context is really of type MapsActivity.
That's my MatchAdapter `package vincenzo.futsal4you;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.MatchResult;
public class MatchAdapter extends ArrayAdapter{
List list=new ArrayList();
String text1=null;
MatchAdapter matchAdapter;
static String id_contatto3="";
String fatto3="";
Player player=new Player();
public MatchAdapter(Context context, int resource) {
super(context, resource);
}
public void add(Match object) {
list.add(object);
super.add(object);
}
#Override
public int getCount() {
return super.getCount();
}
#Override
public Object getItem(int position) {
return super.getItem(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row=convertView;
final Context context = null;
final MatchHolder matchHolder;
final String cc=null;
if (row==null){
LayoutInflater layoutInflater=(LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row=layoutInflater.inflate(R.layout.display_match_row,parent,false);
matchHolder=new MatchHolder();
matchHolder.id_match=(TextView)row.findViewById(R.id.id_partita);
matchHolder.id_contact=(TextView)row.findViewById(R.id.id_contatto);
matchHolder.nome_partita=(TextView)row.findViewById(R.id.nome_partita);
matchHolder.citta=(TextView)row.findViewById(R.id.citta);
matchHolder.indirizzo=(TextView)row.findViewById(R.id.indirizzo);
matchHolder.data=(TextView)row.findViewById(R.id.data);
matchHolder.ora=(TextView)row.findViewById(R.id.ora);
// matchHolder.id_contact=row.findViewById()
matchHolder.join_us = (Button) row.findViewById(R.id.join_us);
row.setTag(matchHolder);
}
else {
matchHolder=(MatchHolder)row.getTag();
}
final Match match=(Match)getItem(position);
// matchHolder.id_contact.setText(mapsActivity.getId_partita().toString());
matchHolder.id_match.setText(match.getId().toString());
matchHolder.nome_partita.setText(match.getName().toString());
matchHolder.citta.setText(match.getCitta().toString());
matchHolder.indirizzo.setText(match.getIndirizzo().toString());
matchHolder.data.setText(match.getData().toString());
matchHolder.ora.setText(match.getOra().toString());
// assert ((MapsActivity) context) != null;
// ((MapsActivity) context).getId_partita();
// final String contact=matchHolder.getId_contatto();
Log.e("BOOOOOO", matchHolder.getId_contatto2());
final String fatto=matchHolder.getId_contatto2();
fatto3=matchHolder.getId_contatto2();
matchHolder.join_us.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//
String fatto2=matchHolder.getId_contatto2();
// final String text3=mapsActivity.getId_partita(cc).toString();
RelativeLayout rl = (RelativeLayout) v.getParent();
RelativeLayout r2 = (RelativeLayout) v.getParent();
// TextView tv = (TextView)rl.findViewById(R.id.nome_partita);
TextView tv = (TextView) rl.findViewById(R.id.id_partita);
TextView tv2 = (TextView) r2.findViewById(R.id.id_contatto);
String id_partita = tv.getText().toString();
String text2 = tv2.getText().toString();
Toast.makeText(getContext(), id_partita, Toast.LENGTH_SHORT).show();
// Toast.makeText(getContext(), matchHolder.setId_contatto(contact), Toast.LENGTH_SHORT).show();
Toast.makeText(getContext(),matchHolder.getId_contatto2(),Toast.LENGTH_SHORT).show();
player.setId_contatto(fatto3);
player.setId_partita(id_partita);
// databaseHelper=new DatabaseHelper(context);
// databaseHelper.insertPlayer2(player);
((MapsActivity)context).getJoinPlayer(player);
Toast pass1=Toast.makeText(getContext(), "One Row JOIN US created !", Toast.LENGTH_SHORT);
pass1.show();
}
});
return row;
}
static class MatchHolder{
TextView id_match,nome_partita,citta,indirizzo,data,ora,id_contact;
Button join_us;
public MatchHolder(){}
public String getId_contatto(String id_contatto) {
return id_contatto;
}
public String getId_contatto2() {
return id_contatto3;
}
public void setId_contatto(String id_contatto) {
id_contatto3 = id_contatto;
}
public MatchHolder(String id_contatto){
id_contatto3=id_contatto;
}
}
}
` So the problem was that i declared a String (id_contatto3) inside a static (inner) class (MatchHolder).Declaring it up to MatchAdapter i solve it somehow, but now i wanna call inside onClick a method that is inside another class (DatabaseHelper that extends SQLiteOpenhelper)..
I can't do ((DatabaseHelper)context).mymethod() So i've done the following "trick"...inside class MapsActivity where i've created a method (JoinPlayer) in such way:
public void JoinPlayer(Player player){
databaseHelper.insertPlayer(player);
}
where insertPlayer(Player) in DatabaseHelper is:
public void insertPlayer(Player player){
try{
db=this.getWritableDatabase();
}
catch(Exception e){
Log.e("ERROR","ERROR");
}
ContentValues contentValues=new ContentValues();
String query="select * from player";
Cursor cursor=db.rawQuery(query,null);
int count=cursor.getCount();
contentValues.put(COLUMN_ID_PLAYER,count);
contentValues.put(COLUMN_ID_MATCH_PLAYER,player.getId_partita());
contentValues.put(COLUMN_ID_CONTACT_PLAYER,player.getId_contatto());
db.insert(TABLE_PLAYER, null, contentValues);
db.close();
}
But Android suggest me to add a null condition(if ((MapsActivity)context)!=null) than ((MapsActivity)context).JoinPlayer(player) but it advise me it will be Always null and that's exactly what I get... I think is the context the main problem but have no clue right now how to solve it. Any Idea?
I want to set Json values into a spinner list. The data I have:
JSONArray lang = jsonObject.getJSONArray("languages");
for (int i = 0; i < lang.length(); i++) {
String language = lang.getString(i);
}
How can i load String values into a spinner list?
ArrayAdapter<String> arrayAdapter = new ArrayAdapter(yourContext, android.R.layout.activity_list_item)
arrayAdapter.addAll(langList); // you need to add your lang.getString(i) to an array
yourSpinner.setAdapter(arrayAdapter);
and voila!
As i understand your problem, you have list of records and you want to show them in spinner in multiple activity.
For this you can create an Class that extends Application Class and create a list in that class.
once You receive response from you web api set data in list of application class.
Now where ever you want to display data in Spinner get it from Application class and render your spinner
See below Example -
public class MyApp extends Application{
private static ArrayList<String> mDataArrayList;
public static ArrayList<String> getmDataArrayList() {
return mDataArrayList;
}
public static void setmDataArrayList(ArrayList<String> mDataArrayList) {
MyApp.mDataArrayList = mDataArrayList;
}
#Override
public void onCreate() {
super.onCreate();
}
}
Call your web api and parse data as you code in your question -
ArrayList<String> mArrayList = new ArrayList<String>();
for (int i = 0; i < lang.length(); i++) {
String language = lang.getString(i);
mArrayList.add(language);
}
//Set Application class list
MyApp.setmDataArrayList(mArrayList);
Now when you want to display data in any class then get list by calling -
ArrayList<String> mArrayList = MyApp.getmDataArrayList();
//Code to display data in Spinner
Hope it will help you.
And dont forgot to add it to manifest of your application -
<application
android:allowBackup="true"
android:name=".MyApp"
....>
....
</application>
I'd suggest you to use Spinner class activity for future usages. Here is the example of spinner activity class (data receiver and displayer):
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
public class mySpinnerClass extends Activity implements
OnItemSelectedListener {
Spinner spinner;
int selectedValue;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.spinner);
selectedValue = -1;
Intent i = getIntent();
dataSelector = i.getStringExtra("MessageText");
// Spinner element
spinner = (Spinner) findViewById(R.id.mySpinner);
// Spinner click listener
spinner.setOnItemSelectedListener(this);
// Loading spinner data
loadSpinnerData();
}
private void loadSpinnerData() {
// Spinner Drop down elements
List<String> lables = yourData.get(dataSelector);
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, lables);
// Drop down layout style - list view with radio button
dataAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
}
public void onItemSelected(AdapterView<?> parent, View arg1, int position, long arg3) {
// TODO Auto-generated method stub
String label = parent.getItemAtPosition(position).toString();
//get the label and do anything you want with it
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
In caller activity:
Intent i = new Intent(getApplicationContext(), mySpinnerClass.class);
i.putExtra("MessageText",yourData);
startActivity(i);
If you want to send non-primitive data (in your example, this is a list) you need to use Serializable type while sending and receiving it. The following link illustrates this technique well:
http://javatechig.com/android/pass-a-data-from-one-activity-to-another-in-android
I am trying to access MainActivity function to my another java class. But i am not able to use these function. Please tell me what else need to be added to get it access.
My code:
Where i am trying to access my MainActivity
package com.example.musicplayer;
**import com.example.musicplayer.MainActivity;**
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class current_song extends Activity implements OnClickListener{
MainActivity ma = new MainActivity();
protected void onCreate(Bundle icicle) {
Bundle extra = getIntent().getExtras();
super.onCreate(icicle);
setContentView(R.layout.songplay_page);
if(extra != null){
String song_name = extra.getString("song_name");
TextView textchange = (TextView)findViewById(R.id.current_song_name);
textchange.setText(song_name);
textchange.setSelected(true);
}
Button btn_pause = (Button)findViewById(R.id.pause_btn);
btn_pause.setOnClickListener(this);
Button btn_next = (Button)findViewById(R.id.next_btn);
btn_next.setOnClickListener(this);
Button btn_prv = (Button)findViewById(R.id.prv_btn);
btn_prv.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "In Onclick ()", Toast.LENGTH_SHORT).show();
switch(v.getId())
{
case R.id.pause_btn:
Toast.makeText(getApplicationContext(), "pause", Toast.LENGTH_SHORT).show();
ma.pause();
break;
case R.id.next_btn:
ma.next();
break;
case R.id.prv_btn:
ma.prv();
break;
}
}
}
Make sure that MainActivity has a zero argument constructor and the access specifier for pause , next and prv function is public.
In response to "i have some methods defined by me stop(), next(), pri() i am trying to access these methods when i click on each button. If you think that "creating a separate common class for sharing all methods" can you please show me 1 example bec i don't know how to access a method from 1 activity to another. "
public class myController{
private MyActivity m;
public myController(MyActivity m){
this.m = m;
}
public void stop(){
m.stop;
}
}
In other classes you initialize in the main activity and pass it the controller object so it can call the stop method
Good day. I'm having some issues with my android project specifically listview. I tried searching for other information here in this site, and implemented some of the answers. However, it is still not working.
The error specifically is
NullPointerException at line 76 at MainActivity
Here is the code of my MainActivity
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
public class MainActivity extends Activity {
final ArrayList<String> studentName = new ArrayList<String>();
ArrayAdapter<String> aa;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView myList = (ListView) findViewById(R.id.listName);
aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, studentName);
myList.setAdapter(aa);
//droid.R.id.list;
//add
Button bAdd = (Button) findViewById(R.id.addstudent);
bAdd.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
startActivity(new Intent("android.intent.action.ADDSTUDENTS"));
}
});
//edit
Button bEdit = (Button) findViewById(R.id.editstudent);
bEdit.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View x) {
startActivity(new Intent("android.intent.action.EDITSTUDENTS"));
}
});
//edit
Button bDelete = (Button) findViewById(R.id.deletestudent);
bDelete.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View x) {
startActivity(new Intent("android.intent.action.DELETESTUDENTS"));
}
});
}
public ArrayList<String> getArray(){
return studentName;
}
public void notifyArray(){
aa.notifyDataSetChanged();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
and line 76 by the way is
aa.notifyDataSetChanged();
Here is my code for the AddStudents class
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class AddStudents extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.add_student);
Button bAddStudents = (Button) findViewById(R.id.add);
final EditText et = (EditText) findViewById(R.id.student_name);
bAddStudents.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
MainActivity as = new MainActivity();
as.getArray().add(et.getText().toString());
as.notifyArray();
finish();
}
});
Button bBack = (Button) findViewById(R.id.backadd);
bBack.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
finish();
}
});
}
}
and the xml part with the list view is
<ListView
android:id="#+id/listName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
I hope you can help me cause I want to also learn what my mistakes are. I can add other information if you want.
In your AddStudents class, you're calling notifyArray() right after you instantiated MainActivity. MainActivity.onCreate() will not be called just by instantiating it.
Instantiating your MainActivity there is probably not what you want anyway (because that object will be disposed directly after the onClick handler is done).
What you want instead is to access the existing instance of MainActivity. For that, add a reference to the current instance to a static member of your MainActivity class, e.g.
public class MainActivity extends Activity {
public static MainActivity activity;
#Override
protected void onCreate(Bundle savedInstanceState) {
activity = this;
}
}
Then in your AddStudent class access it via
MainActivity.activity.notifyArray()
This is not the most beautiful way to solve your issue, but it works as long as you can be sure to only have one MainActivity instance. (If not, you could make the array itself static; or create a Singleton wrapper class for it.)
notifyArray() is being called before onCreate.
Try calling getArray().add(et.getText().toString()); and notifyArray(); inside onResume() of MainActivity and NOT from AddStudentActivity( not recommended!)
So onResume() you would ideally want to add a new student to the list, so in your case, you can retrieve the student name using a common sharable object like a hashtable or somethiing similar, make it a singleton, and use it from anywhere in the applciation
The common class may go something like:
class CommonHashtable{
private static Hashtable<String, Object> commonHashtable = null;
public static getInstance(){
if(commonHashtable == null)
commonHashtable = new Hashtable<String, Object>();
return commonHashtable;
}
on getInstance(), it returns a commonHashtable which can be used to store values temporarily!
so, add this on addbutton click event
Hashtable hash = CommonHashtable.getInstance();
hash.put("NEW_STUDENT_NAME", et.getText().toString());
and add this in you onResume() of MainActivity
Hashtable hash = CommonHashtable.getInstance();
Object studentName = (String) hash.get("NEW_STUDENT_NAME");
if(studentName != null){
notifyArray();
}