I have a program in android where spinner gets the data dynamically from rest services. what i want to achieve is when the first spinner loads its value, the selected value loads the value of 2nd and third spinner. i want to disable the click of 2nd and third spinner till the spinner gets populated are loaded in all the spinner.
I call the function of populating 2nd & 3rd spinner in the end of the program.
public void addItemsOnSpinner1()
{
Bundle extras = getIntent().getExtras();
String strEmployeeID="";
if (extras != null) {
String value = extras.getString("new_variable_name");
strEmployeeID = value;
}
JSONObject login = new JSONObject();
try
{
login.put("EmployeeID",strEmployeeID);
//login.put("Password", etCountry.getText().toString());
JSONObject finaldata = new JSONObject();
finaldata.put("ProjectRequest", login);
final ConnectToServer connect = new ConnectToServer();
connect.extConnectToServer(HourlyEntry.this,new ConnectToServer.Callback()
{
public void callFinished(String result)
{
// Toast.makeText(getBaseContext(), result, Toast.LENGTH_LONG).show();
JSONObject resp = null;
try
{
resp = new JSONObject(result);
// Toast.makeText(getBaseContext(), result, Toast.LENGTH_LONG).show();
JSONObject Login1Result = resp.getJSONObject("ProjectResult");
JSONArray DepartmentDetails = Login1Result.getJSONArray("ProjectDetails");
// String strMessage = Login1Result.getString("message");
// Toast.makeText(getBaseContext(), Login1Result.getString("ProjectDetails"), Toast.LENGTH_LONG).show();
// List<String> list = new ArrayList<String>();
if (!Login1Result.getString("ProjectDetails").equalsIgnoreCase("null"))
{
//JSONArray DepartmentDetails = Login1Result.getJSONArray("ProjectDetails");
m_Project_list = new ArrayList<String>();
m_projectID_list = new ArrayList<String>();
for (int i = 0; i < DepartmentDetails.length(); i++)
{
JSONObject m_DepartmentDetails = DepartmentDetails.getJSONObject(i);
// Toast.makeText(getBaseContext(),m_DepartmentDetails.toString() , Toast.LENGTH_LONG).show();
if (!m_DepartmentDetails.getString("ProjectName").equalsIgnoreCase("null")&& !m_DepartmentDetails.getString("ProjectName").equalsIgnoreCase(""))
{
// list.add(m_DepartmentDetails.getString("ProjectName"));
m_Project_list.add(m_DepartmentDetails.getString("ProjectName"));
// Toast.makeText(getBaseContext(), m_DepartmentDetails.getString("ProjectName"), Toast.LENGTH_LONG).show();
}
if (!m_DepartmentDetails.getString("ProjectID").equalsIgnoreCase("null")&& !m_DepartmentDetails.getString("ProjectID").equalsIgnoreCase(""))
{
m_projectID_list.add(m_DepartmentDetails.getString("ProjectID"));
//Toast.makeText(getBaseContext(), m_DepartmentDetails.getString("ProjectID"), Toast.LENGTH_LONG).show();
String strProjectID="";
String item2 = m_DepartmentDetails.getString("ProjectID");
strProjectID = item2;
}
}
}
s1 = (Spinner) findViewById(R.id.spinnerL);
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, R.layout.spin,m_Project_list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);
if (m_projectID_list.contains(m_ProjectID))
{
s1.setSelection(m_projectID_list.indexOf(m_ProjectID));
}
}
catch (final JSONException e)
{
}
}
}, "http://aapna.azurewebsites.net/Service1/Project", finaldata,
"POST");
connect.execute(finaldata);
s1.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> adapter, View v,
int position, long id) {
// On selecting a spinner item
final String item1 = adapter.getItemAtPosition(position).toString();
final String SelectedProjectID = m_projectID_list.get(s1.getSelectedItemPosition());
// Toast.makeText(getApplicationContext(),
// SelectedProjectID, Toast.LENGTH_LONG).show();
// Showing selected spinner item
// Toast.makeText(getApplicationContext(),
// "Selected : " + item1, Toast.LENGTH_LONG).show();
s2.setClickable(false);
s3.setClickable(false);
addItemsOnSpinner2(SelectedProjectID);
s2.setClickable(true);
addItemsOnSpinner3(SelectedProjectID);
s3.setClickable(true);
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
catch (Exception e) {
Log.d("InputStream", e.getLocalizedMessage());
}
}
Try this..
Change your first element from m_Project_list ArrayList as Select
And after user selecting spinner you can do other operation below codes inside onCreate
Code
s1.setSelection(0);
s1.setOnItemSelectedListener(new OnItemSelectedListener(){
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int pos, long arg3) {
// TODO Auto-generated method stub
if(pos == 0){
s2.setEnabled(false);
s3.setEnabled(false);
}
else{
// do something
addItemsOnSpinner2(SelectedProjectID);
s2.setEnabled(true);
addItemsOnSpinner3(SelectedProjectID);
s3.setEnabled(true);
}
}
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
EDIT
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
Log.i("=========="," handler == > ");
Toast.makeText(getBaseContext(), "handler", Toast.LENGTH_LONG).show();
}
}, 5000);
The only solution I got is to use delay function to solve this kind of spinner as told to me by hariharan.
ADD these two statements in spinner 1 function
s1.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> adapter, View v,
int position, long id)
{
// On selecting a spinner item
final String item1 = adapter.getItemAtPosition(position).toString();
final String SelectedProjectID = m_projectID_list.get(s1.getSelectedItemPosition());
s2.setEnabled(false);
s3.setEnabled(false);
addItemsOnSpinner2(SelectedProjectID);
addItemsOnSpinner3(SelectedProjectID);
delay1();
//
}
#Override
public void onNothingSelected(AdapterView<?> arg0)
{
// TODO Auto-generated method stub
}
});
then use the below function
public void delay1()
{
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run()
{
s2.setEnabled(true);
s3.setEnabled(true);
}
}, 3000);
}
Related
I'm building an App that receives all wifi networks arround my house.
All wifi networks are being listed inside a Listview.
Now I would like to open a new activity when some listview item is clicked. But before that I would like to get the SSID from the selected Item.
I'm using onItemClick to get the position from the item and is working fine. The problem that I'm getting is that when I click at some item, I get a different SSID from the current selected item, the values are being desplayed like that:
WIFI 1 - When I click here I get the SSID from WIFI 3
WIFI 2 - When I click here I get the SSID from WIFI 2
WIFI 3 - When I click here I get the SSID from WIFI 1
Instead of getting the SSID from the wifi 1 when I click at wifi one and etc.
Can you guys check what am I doing wrong?
My code:
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textStatus = (TextView) findViewById(R.id.textView1);
buttonScan = (Button) findViewById(R.id.button1);
lv = (ListView)findViewById(R.id.text);
lv.setClickable(true);
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if (wifi.isWifiEnabled() == false)
{
Toast.makeText(getApplicationContext(), "wifi is disabled..making it enabled", Toast.LENGTH_LONG).show();
wifi.setWifiEnabled(true);
}
this.adapter = new SimpleAdapter(MainActivity.this, arraylist, android.R.layout.simple_list_item_1, new String[] { ITEM_KEY }, new int[] { android.R.id.text1 });
lv.setAdapter(this.adapter);
registerReceiver(new BroadcastReceiver()
{
#Override
public void onReceive(Context c, Intent intent)
{
results = wifi.getScanResults();
size = results.size();
}
}, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
}
#Override
protected void onResume() {
super.onResume();
final Handler handler = new Handler();
Runnable refresh = new Runnable() {
#Override
public void run() {
test();
handler.postDelayed(this, 8000);
}
};
handler.postDelayed(refresh, 2000);
}
private void test() {
{
arraylist.clear();
wifi.startScan();
Toast.makeText(this, "Scanning...." + size, Toast.LENGTH_SHORT).show();
try
{
size = size - 1;
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Log.e("", "" + results.get(arg2).SSID);
}
});
while (size >= 0)
{
LinkedHashMap<String, String> item = new LinkedHashMap<String, String>();
String BSSID = results.get(size).BSSID;
int frequency = results.get(size).frequency;
if(!results.get(size).SSID.equals("FET")) {
item.put(ITEM_KEY, results.get(size).SSID.concat(""));
arraylist.add(item);
}
size--;
adapter.notifyDataSetChanged();
}
}
catch (Exception e)
{ }
}
}
}
Reverse the order in which you add your list items to arraylist
try
{
size = 0;
...
while (size < results.size())
{
...
arraylist.add(item);
...
size++;
...
}
}
this is my code, If add the if statement in line No 105 then program crashes, if i removed this then my code is working. But without this i can't solve my code. Please can anyone tell me what could be the problem or what am i doing wrong?
public class SMSDetails extends Activity {
Spinner examSpinnerSMS,yearSpinnerSMS,boardSpinnerSMS;
private String[] examinationStrings;
private String[] yearStrings;
private String[] boardStrings;
int index;
private String mSelectedItemExam,mSelectedItemYear,mSelectedItemBoard;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_smsdetails);
//initialize view
examSpinnerSMS = (Spinner)findViewById(R.id.spnrExamination);
yearSpinnerSMS=(Spinner)findViewById(R.id.spnrYear);
boardSpinnerSMS=(Spinner)findViewById(R.id.spnrBoard);
//initialize data source
examinationStrings = getResources().getStringArray(R.array.Examination);
yearStrings = getResources().getStringArray(R.array.YearArray);
boardStrings = getResources().getStringArray(R.array.Board);
//initialize view
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, examinationStrings);
ArrayAdapter<String> adapter1= new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, yearStrings);
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, boardStrings);
//bind adapter and view
examSpinnerSMS.setAdapter(adapter);
yearSpinnerSMS.setAdapter(adapter1);
boardSpinnerSMS.setAdapter(adapter2);
//work with the spinners
examSpinnerSMS.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View view,int arg2, long arg3) {
//index = examSpinnerSMS.getSelectedItemPosition();
mSelectedItemExam=arg0.getSelectedItem().toString();
//Toast.makeText(getApplicationContext(),"You have selected "+mSelectedItemExam,Toast.LENGTH_LONG).show();
// TODO Auto-generated method stub
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
);
yearSpinnerSMS.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View view,int arg2, long arg3) {
//index = examSpinnerSMS.getSelectedItemPosition();
mSelectedItemYear=arg0.getSelectedItem().toString();
//Toast.makeText(getApplicationContext(),"You have selected "+mSelectedItemYear,Toast.LENGTH_LONG).show();
// TODO Auto-generated method stub
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
);
boardSpinnerSMS.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View view,int arg2, long arg3) {
index = examSpinnerSMS.getSelectedItemPosition();
mSelectedItemBoard=arg0.getSelectedItem().toString();
//Toast.makeText(getApplicationContext(),"You have selected "+mSelectedItemBoard,Toast.LENGTH_LONG).show();
// TODO Auto-generated method stub
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
);
//Log.i("problem", "problem");
//problem is here
if (mSelectedItemExam.equals("Select One")||mSelectedItemYear.equals("Select One")|| mSelectedItemBoard.equals("Select One")) {
Toast.makeText(getApplicationContext(), "Enter all the value", Toast.LENGTH_SHORT).show();
}
//Log.i("problem", "problem");
}
public void Submit(View view) {
String fm = mSelectedItemExam+" "+mSelectedItemBoard+" "+mSelectedItemYear;
//Log.i("problem", "problem");
try {
sendSMS("5556", fm);
Toast.makeText(getApplicationContext(), "SMS sent",
Toast.LENGTH_LONG).show();
}
catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again.",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
private void sendSMS(String phoneNumber, String message)
{
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.smsdetails, menu);
return true;
}
}
do you mean that you need to add an if statement in this lines?:
catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again.",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
Please add the statement where it is not compiling.
mSelectedItemExam is probably null because none has been selected at the time you're doing
mSelectedItemExam.equals("Select One")
Learn how to use the Logcat and next time post a stracktrace :)
I am trying to get values from server and retrieved response from server, the details responsed from server are need to be displayed in a listview, i achieved that too, but while onitemclick process only first row in list view performs the click action but it is not performing for the remaining rows, how can i achieve it, dat is whatever the row and item i'm selecting it has to be processed by my code, here is my code for the reference, .........
public void userInterface() throws JSONException
{
if(json_user.get(0) != null)
{
downloadList1 = (ListView)findViewById(R.id.lvinbox);
populateData();
downloadList1.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
// TODO Auto-generated method stub
fma=(TextView)findViewById(R.id.src);
st=(TextView)findViewById(R.id.sub);
fma.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
String fm=fma.getText().toString();
String s=st.getText().toString();
Intent m = new Intent(getApplicationContext(), InActivity.class);
m.putExtra("f", fm);
m.putExtra("s", s);
startActivity(m);
}
});
st.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
String fm=fma.getText().toString();
String s=st.getText().toString();
Intent m = new Intent(getApplicationContext(), InActivity.class);
m.putExtra("f", fm);
m.putExtra("s", s);
startActivity(m);
}
});
}
});
}
else
{
Toast.makeText(getApplicationContext(),"Empty", Toast.LENGTH_LONG).show();
finish();
Intent menu = new Intent(getApplicationContext(), MenActivity.class);
menu.putExtra("username", dest);
startActivity(menu);
}
}
public void populateData() throws JSONException
{
resultVector = new Vector<ListDataItemInbox>();
int len = json_user.length();
System.out.println("length--------------------->"+len);
for(int i=0;i<len;i++)
{
JSONObject obj=json_user.getJSONObject(i);
listData = new ListDataItemInbox();
listData.sets(obj.getString(KEY_S));
listData.setd(obj.getString(KEY_D));
resultVector.add(listData);
myHandler.post(myRunnable);
}
}
private Handler myHandler = new Handler();
private Runnable myRunnable = new Runnable()
{
public void run()
{
customListAdapter = new ListViewAdapterInbox(InActivity.this);
customListAdapter.setResultsData(resultVector);
downloadList1.setAdapter(customListAdapter);
}
};
You can do something like this.
make the ArrayList in list adapter class
ArrayList<Integer> selectedIds = new ArrayList<Integer>();
and create this method also in that same class.
public void toggleSelected(Integer position){
selectedIds.clear();
selectedIds.add(position);
}
Now whenever you click on any item of listview pass that item position to this method. And inside your getView method set the check before setting the text. something like this..
if (selectedIds.contains(position)){
----- your code ----
}else{
----- your code ----
}
it perform the operation only on selected position . Try it.!
My need is to
create a dynamic spinner on a button click
select the spinner values and set the values into an edit text field.
For this I have created a dynamic spinner programatically. Put that code inside button click listener. Its working fine upto here.
but the setOnitemSelectedListener of the dynamic spinner is not at all working.. there are no errors in the Logcat... please help me..
------------ These are the methods inside onCreate ------------
Spinner spnOutHospitalList = new Spinner(Referance.this);
// list button on click event
btnList = (Button) findViewById(R.id.btn_list);
btnList.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
// function to create spinner dynamically
createDynamicSpinner();
}
});
// Out Hospital List Spinner on item click listener
spnOutHospitalList.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1,int position, long arg3) {
// TODO Auto-generated method stub
outHospitalName = hospitalNameListArray.get(position);
outHospital.setText(outHospitalName);
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
------------ These are the functions outside onCreate but inside the Activity------------
// to create spinner dynamically
private void createDynamicSpinner() {
// TODO Auto-generated method stub
spnOutHospitalList.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
loadOutHospitalListSpinner();
spnOutHospitalList.performClick();
}
// to load out hospital/ clinic data into spinner
private void loadOutHospitalListSpinner() {
// TODO Auto-generated method stub
try {
if (getFirstRun()) {
sampleDB = dbAdapter.getDatabase();
setRunned();
}
else {
sampleDB = dbAdapter.getWritableDatabase();
}
Cursor c1 = sampleDB.rawQuery("select DISTINCT EPR_OUT_HOSPITAL from EMR_PT_REFERNCE",null);
System.out.println("count is " + c1.getCount());
if (c1 != null && c1.getCount() != 0) {
hospitalNameListArray.clear();
if (c1.moveToFirst()) {
do {
hospitalNameListArray.add(c1.getString(c1.getColumnIndex("EPR_OUT_HOSPITAL")));
} while (c1.moveToNext());
}
}
c1.close();
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, hospitalNameListArray);
// dropdownlist
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spnOutHospitalList.setAdapter(dataAdapter);
}
catch (Exception e) {
// TODO: handle exception
System.out.println("CAT LIST ERROR IS: " + e.getMessage());
}
}
Try this
Write setOnItemSelectedListener inside createDynamicSpinner
private void createDynamicSpinner() {
//Remove this line from top in your code and add here
Spinner spnOutHospitalList = new Spinner(Referance.this);
spnOutHospitalList.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
//Pass Spinner Object to this function to load data in it!
loadOutHospitalListSpinner(spnOutHospitalList);
spnOutHospitalList.performClick();
spnOutHospitalList.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1,int position, long arg3) {
// TODO Auto-generated method stub
outHospitalName = hospitalNameListArray.get(position);
outHospital.setText(outHospitalName);
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
I am trying to pass information form one Activity to the other and while doing that I would like to have a progress dialog show. Mainly when the second activity is processing the information. I have been reading up and the proper way of doing it seems to be asynctask. Or is there another way of doing it?
Here is my code: Activity one
public class SearchActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
final EditText edittext = (EditText) findViewById(R.id.edittext);
edittext.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN)
&& (keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
String query = edittext.getText().toString();
// gets the text and makes sure its a string
Intent intent = new Intent(SearchActivity.this,
DissertationActivity.class);
intent.putExtra("query1", query);
startActivity(intent);
return true;
}
return false;
}
});
final Button button = (Button) findViewById(R.id.searchButton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String query = edittext.getText().toString();
// gets the text and makes sure its a string
Intent intent = new Intent(SearchActivity.this,
DissertationActivity.class);
intent.putExtra("query1", query);
startActivity(intent);
}
});
}
}
This is the Second activity:
public class DissertationActivity extends ListActivity {
/** Called when the activity is first created. */
public ArrayList<String> book_Array = new ArrayList<String>();
ArrayAdapter<String> adapter;
String href = "";
String href1 = "";
String search_Word = "";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
search_Word = extras.getString("query1");
adapter = new ArrayAdapter<String>(this, R.layout.list_item_1,
book_Array);
setListAdapter(adapter);
ListView lv = getListView();
lv.setTextFilterEnabled(true);
try {
Document doc = null;
Document guestLink = null;
guestLink = Jsoup.connect("https://aulib.abdn.ac.uk:443/F").get();
Element link = guestLink.select("p > a").first();
href1 = link.attr("href");
href = href1.substring(0, href1.length() - 2); // removes -0 from
// the
// href_Array.add(href); //adds href to the array because string
// wont add to the public var.
doc = Jsoup.connect(
href + "&request=" + search_Word
+ "&find_code=WRD&adjacent=N&x=0&y=0").get();
// System.out.println(doc);
Elements headings = doc.select("td:eq(3)");
// System.out.println(headings);
for (Element heading : headings) {
// System.out.println(heading.text());
String j = heading.text();
book_Array.add(j);
}
} catch (IOException e) {
e.printStackTrace();
}
book_Array.remove(0);
adapter.notifyDataSetChanged();
book_Array.remove(1);
adapter.notifyDataSetChanged();
book_Array.remove(2);
adapter.notifyDataSetChanged();
book_Array.remove("Search");
adapter.notifyDataSetChanged();
book_Array.remove(" | ");
adapter.notifyDataSetChanged();
book_Array.remove(0);
adapter.notifyDataSetChanged();
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a, View v, int position,
long id) {
// Context context = getApplicationContext();
int query = position;
// String text = book_Array.get(position);
// int duration = Toast.LENGTH_SHORT;
// Toast toast = Toast.makeText(context,
// String.valueOf(position), //shows the postion in the array
// list
// duration);
// toast.show();
Intent intent = new Intent(DissertationActivity.this,
FullDetailsActivity.class);
intent.putExtra("href", href);
intent.putExtra("query1", (int) query);
intent.putExtra("search_Word", search_Word);
startActivity(intent);
}
});
}
}
I tried using:
this.pd = ProgressDialog.show(this, "Working..", "Downloading Data...",
true, false);
But that didn't work.
How would I go about, so that it displays a progress dialog in between the activities?
Thanks for your help!
Calling ProgressDialog.show will block the UI thread. So the progress dialog/bar will not show up until the method has returned. So we can create a thread for our method to run within it. This will avoid blocking the main UI Thread.
Sample code -
ProgressDialog spinnerDialog = ProgressDialog.show(
Placeholder.this, "","Your text ", true);
new Thread(new Runnable() {
public void run() {
//your method code
return;
}
}).start();