I have 3 menu items in action bar when I click any one of them data retrieved from webservice which is working fine. but while retrieving I need to show Progress dialog in the screen .I have tried different ways like starting in new thread, AsyncTask. But finally stuck. Please can anyone help me out. Here is my complete code.
import hello.aws.graph.BatteryGraph;
public class BatteryGraph extends AppCompatActivity {
static ProgressDialog dialog = null;
static String value;
public static Menu menu;
static ArrayList<TrackingBean> Battery;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_line_chart);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit();
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent newIntent;
switch (item.getItemId()) {
case R.id.bb_menu_favorites:
value="favorites";
getData(value);
getSupportFragmentManager().beginTransaction().replace(R.id.container, new PlaceholderFragment()).commit();
break;
case R.id.bb_menu_mylist:
value="mylist";
getData(value);
getSupportFragmentManager().beginTransaction().replace(R.id.container, new PlaceholderFragment()).commit();
break;
case R.id.bb_menu_recents:
value="myrecents";
getData(value);
getSupportFragmentManager().beginTransaction().replace(R.id.container, new PlaceholderFragment()).commit();
break;
}
return true;
}
public void getData(final String value)
{
AsyncCallWS task = new AsyncCallWS();
try {
task.execute().get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
/**
* A fragment containing a line chart.
*/
public static class PlaceholderFragment extends Fragment {
private LineChartView chart;
private LineChartData data;
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
setHasOptionsMenu(true);
View rootView = inflater.inflate(R.layout.fragment_line_chart, container, false);
chart = (LineChartView) rootView.findViewById(R.id.chart);
generateData();
return rootView;
}
private void generateData() {
/****This method used to Plot points on graph ****/
}
}
private class AsyncCallWS extends AsyncTask<Void, Void, Void> {
#Override
protected void onPreExecute() {
dialog = new ProgressDialog(BatteryGraph.this, R.style.MyTheme);
dialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
dialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.cp_bar));
dialog.setCancelable(false);
dialog.show();
getSupportFragmentManager().beginTransaction().replace(R.id.container, new PlaceholderFragment()).commit();
}
#Override
protected Void doInBackground(Void... params) {
Battery=WebService.getDataFromWS(value);
return null;
}
#Override
protected void onPostExecute(Void result) {
if(dialog!=null||dialog.isShowing()) {
dialog.dismiss();
}
}
}
}
activity_line_chart.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="hello.aws.graph.BatteryGraph"
tools:ignore="MergeRootFrame" />
fragment_line_chart.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="hello.aws.graph.BatteryGraph$PlaceholderFragment" >
<LinearLayout
android:id="#+id/l1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin1top"
android:orientation="vertical">
<lecho.lib.hellocharts.view.LineChartView
android:id="#+id/chart"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</lecho.lib.hellocharts.view.LineChartView>
</LinearLayout>
</RelativeLayout>
i hope it will help u...
private class AsyncCallWS extends AsyncTask<Void, Void, Void> {
#Override
protected void onPreExecute() {
pDialog = new ProgressDialog(getActivity());//here activity name or if u are using fragment put getActivity()
pDialog.setMessage("Loading...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.setCanceledOnTouchOutside(false);
pDialog.show();
getSupportFragmentManager().beginTransaction().replace(R.id.container, new PlaceholderFragment()).commit();
}
#Override
protected Void doInBackground(Void... params) {
Battery=WebService.getDataFromWS(value);
return null;
}
#Override
protected void onPostExecute(Void result) {
if(dialog!=null||dialog.isShowing()) {
pDialog.dismiss();
}
}
}
Related
I have two fragments in my Activity : Fragment_A and Fragment_B.
In Fragment A, I created an AsyncTask (when the user "swipeRefreshes" the screen). In the onPostExecute() of this task, I want to display a Toast :
private class MakeRequestTask extends AsyncTask<Void, Void, List<String>> {
private Exception mLastError = null;
MakeRequestTask() {
//Some stuff
}
#Override
protected List<String> doInBackground(Void... params) {
//Some stuff
}
#Override
protected void onPreExecute() {
//Some stuff
}
#Override
protected void onPostExecute(List<String> output) {
swipeRefreshLayout.setRefreshing(false);
Toast.makeText(getActivity(), "TO_DISPLAY", Toast.LENGTH_SHORT).show();
}
}
#Override
protected void onCancelled() {
swipeRefreshLayout.setRefreshing(false);
//Some stuff
}
}
If the user changes from Fragment_A to Fragment_B before the AsyncTask finishes, I get a crash:
java.lang.IllegalStateException: Fragment Fragment_A not attached to a context.
I know how to avoid the crash (by adding the condition isAdded()), but I want my Toast to be displayed no matter which Fragment is displayed/alive on top of my Activity.
1stly I would like to suggest you, please make your MakeRequestTask inner class as static as this can be a memory leak.
For your question, You need to pass the context to the class like below:
private static class MakeRequestTask extends AsyncTask<Void, Void, List<String>> {
private Exception mLastError = null;
private WeakReference<Context> weakReference;
MakeRequestTask(Context context) {
//Some stuff
weakReference = new WeakReference<>(context);
}
#Override
protected List<String> doInBackground(Void... params) {
//Some stuff
}
#Override
protected void onPreExecute() {
//Some stuff
}
#Override
protected void onPostExecute(List<String> output) {
// swipe layout will not be shown if fragment is not visible or destroyed
if (isFragmentVisible) {
swipeRefreshLayout.setRefreshing(false);
}
// toast will be shown no matter what fragment is visible
if (weakReference != null) {
Context context = weakReference.get();
if (context != null) {
Toast.makeText(context, "TO_DISPLAY", Toast.LENGTH_SHORT).show();
}
}
}
#Override
protected void onCancelled() {
if (isFragmentVisible) {
swipeRefreshLayout.setRefreshing(false);
}
//Some stuff
}
}
Try this way
Declare a boolean in Fragment_A
private boolean isFragmentVisible=false;
In Fragment_A class
Make this boolean true in onCreateView() of this Fragment_A
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.lyourlayout, container, false);
isFragmentVisible = true;
return view;
}
And make this boolean false in onDestroyView() of this fragment A
#Override
public void onDestroyView() {
super.onDestroyView();
isFragmentVisible = false;
}
Finally use it in Asyntask of Fragment_A like this
private class MakeRequestTask extends AsyncTask<Void, Void, List<String>> {
private Exception mLastError = null;
MakeRequestTask() {
//Some stuff
}
#Override
protected List<String> doInBackground(Void... params) {
//Some stuff
}
#Override
protected void onPreExecute() {
//Some stuff
}
#Override
protected void onPostExecute(List<String> output) {
// swipe layout will not be shown if fragment is not visible or destroyed
if(isFragmentVisible){
swipeRefreshLayout.setRefreshing(false);
}
// toast will be shown no matter what fragment is visible
Toast.makeText(getActivity(), "TO_DISPLAY", Toast.LENGTH_SHORT).show();
}
#Override
protected void onCancelled() {
if(isFragmentVisible){
swipeRefreshLayout.setRefreshing(false);
}
//Some stuff
}
}
Or you can just use and interface or an EventBus in the onPostExecute method, and show the Toast inside the activity.
#Override
protected void onPostExecute(List<String> output) {
swipeRefreshLayout.setRefreshing(false);
activityContractInterface.showToast()
}
}
And in your Activity:
#Override
public void showToast(){
Toast.makeText(getActivity(), "TO_DISPLAY", Toast.LENGTH_SHORT).show();
}
Or the EventBus approach:
#Override
protected void onPostExecute(List<String> output) {
swipeRefreshLayout.setRefreshing(false);
EventBus.getDefault().post(new ShowToastEvent())
//just create an empty class, hope you know what EventBus is
}
And in your activity:
#Subscribe(threadMode = ThreadMode.Main){
Toast.makeText(getActivity(), "TO_DISPLAY", Toast.LENGTH_SHORT).show();
}
EventBusLibrary
I'm also getting it in a precise context and the solution given here (IllegalStateException: Can not perform this action after onSaveInstanceState with ViewPager) don't work.
Here is the code: Should be a working code for test; I hope.
MainActivity.java
public class MainActivity extends FragmentActivity {
final static int INIT_NETWORK_DONE = 1;
final static int EXIT_APPLICATION = -1;
private Site site = new Site(this);
private WifiManager wifi = null;
Handler mHandler = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
site.setUrls();
if (savedInstanceState == null) {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
fragmentTransaction.replace(R.id.frame_container, new Fragment_init(site)).commit();
}
}
. . .
#Override
public void onSaveInstanceState(Bundle saveInstanceState) {
//super.onSaveInstanceState(saveInstanceState);
}
}
Fragment_init.java
public class Fragment_init extends Fragment {
Fragment fragment = null;
private InitTask mInitTask = null;
// Taille maximale du téléchargement
public final static int MAX_SIZE = 100;
// Identifiant de la boîte de dialogue
public final static int ID_DIALOG = 0;
public final static int DO_INIT_WIFI = 1;
private Site site = null;
public Fragment_init() {
}
public Fragment_init(Site _site) {
site = _site;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_init, container, false);
return rootView;
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (savedInstanceState == null) {
Animation animation = AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.animator.welcome_anim);
ImageView logoSite = (ImageView)getActivity().findViewById(R.id.imageAvenArmand);
logoSite.startAnimation(animation);
// Do the init
mInitTask = new InitTask(Fragment_init.this, site, getFragmentManager());
// On l'exécute
mInitTask.execute(0);
}
}
// L'AsyncTask est bien une classe interne statique
static class InitTask extends AsyncTask<Integer, Integer, Integer> {
// Référence faible à l'activité
private Fragment_init mActivity = null;
private Site site = null;
Context context = null;
private FragmentManager fragmentManager = null;
public InitTask (Fragment_init pActivity, Site pSite, FragmentManager _fragmentManager) {
mActivity = pActivity;
context = mActivity.getActivity();
site = pSite;
fragmentManager = _fragmentManager;
}
#Override
protected void onPreExecute () {
}
#Override
protected void onPostExecute (Integer result) {
if(result != 1) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mActivity.getActivity());
alertDialog.setTitle(R.string.label_titleAlertInit);
} else {
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
fragmentTransaction.replace(R.id.frame_container, new Fragment_selectLanguage(site)).commitAllowingStateLoss();
}
}
#Override
protected Integer doInBackground (Integer... arg0) {
URL url = null;
BufferedInputStream buf;
ArrayList<Language> languages = null;
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
}
return 1;
}
#Override
protected void onProgressUpdate (Integer... prog) {
}
#Override
protected void onCancelled () {
}
private int processStream(InputStream inputStream) {
// Création du parser XML
XmlPullParserFactory factory;
int lineNumber = 0;
return (1);
}
}
#Override
public void onSaveInstanceState(Bundle saveInstanceState) {
//super.onSaveInstanceState(saveInstanceState);
}
}
activity_main.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:screenOrientation="portrait"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.cabbonline.ndguidelt.MainActivity" >
</FrameLayout>
fragment_init.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/fragmentInit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.cabbonline.ndguidelt.MainActivity" >
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:src="#drawable/launcher_icon" />
</RelativeLayout>
Anyway, I think that not calling super.onSaveInstanceState() should cause problem on context saving no?
so if you rotate the screen when the image is fading, you should get IllegalStateException on call on commit()
So my workaround is to prevent the screen rotation during this transitional screen. Ok that's ok for me but I doubt it could be an answer for most of you. anyway, it could help.
So I call this in onCreateView() in fragment_init().
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
And I then call this in onCreateView() in the next fragment:
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
:-/
Any other idea?
Use commitAllowingStateLoss() instead of commit()
if (savedInstanceState == null) {
FragmentTransaction fragmentTransaction =getSupportFragmentManager().beginTransaction();
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
fragmentTransaction.replace(R.id.frame_container, new Fragment_init(site)).commitAllowingStateLoss();
}
You should see this blog about on how to avoid that exception: http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html
So I solved my problem using the wonderfull message handler implementation explained here:
How to handle Handler messages when activity/fragment is paused
Thx to Akagami which pointed me on the post.
Regards,
I have a main activity, which has a fragment inside, that calls an Asynctask.
Main Activity - The main activity has a ViewPager that loads the fragment.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.viewPager = (ViewPager)findViewById(R.id.pager);
this.mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(mAdapter);
/**
* on swiping the viewpager make respective tab selected
* */
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageSelected(int position) {
// on changing the page
// make respected tab selected
//actionBar.setSelectedNavigationItem(position);
//Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)",
//Toast.LENGTH_LONG).show();
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
#Override
public void onPageScrollStateChanged(int arg0) {
}
});
Fragment - Makes Call to service
public class SomeFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.article_view, container, false);
ServiceHelper srv = new ServiceHelper(getActivity(), "GetHomeImage", postParameters, 2);
AsyncTask<String, Void, String> request = srv.execute();
return view;
}
}
Async Task Class - Show Progressdialog and make requests
public class ServiceHelper extends AsyncTask<String, Void, String> {
public ServiceHelper(Context c, String method, HashMap<String, Object> parameters, int requestType){
context = c;
this.method = method;
this.parameters = parameters;
this.requestType = requestType;
}
protected void onPreExecute(){
progressDialog = ProgressDialog.show(context, "Requisição", "Chamando Serviço", true, false);
}
protected String doInBackground(String... params) {
do stuff...
}
protected void onPostExecute(String result) {
progressDialog.dismiss();
}
}
The problem I'm facing is that the fragment is called, the request is made, but the Progessdialog only appears when the fragment is shown.
It's possible to show the Progressdialog when the call is made?
Thanks.
I think the simple way here is show progress dialog before call to execute AsyncTask. for closing progress dialog you should add a Listener to ServiceHelper and listen it to dismiss dialog on cancel or completion of task. here is code:
final Dialog progressDialog = ProgressDialog.show(context, "Requisição", "Chamando Serviço", true, false);
ServiceHelper srv = new ServiceHelper(getActivity(), "GetHomeImage", postParameters, 2);
srv.setListener(new ServiceHelperListener() {
public void onCancel() {
progressDialog.dismiss();
}
public void onCompelte() {
progressDialog.dismiss();
}
});
AsyncTask<String, Void, String> request = srv.execute();
and ServiceHelper class and Listener:
public class ServiceHelper extends AsyncTask<String, Void, String> {
private ServiceHelperListener mListener;
public ServiceHelper(Context c, String method, HashMap<String, Object> parameters, int requestType){
context = c;
this.method = method;
this.parameters = parameters;
this.requestType = requestType;
}
public void setListener(ServiceHelperListener listener) {
this.mListener = listener;
}
protected void onPreExecute(){
}
protected String doInBackground(String... params) {
do stuff...
}
protected void onPostExecute(String result) {
if (mListener != null) {
mListener.onCompelte();
}
}
#Override
protected void onCancelled(String s) {
super.onCancelled(s);
if (mListener != null) {
mListener.onCancel();
}
}
}
public interface ServiceHelperListener {
public void onCancel();
public void onCompelte();
}
I'm with a little problem that is driving me crazy. I'm using a AsyncTask in a retained Fragment to update a progressDialog in my activity. I'm using callbacks to send the progress from my fragment.
The problem is: When I rotate my screen it simply stops do update the progressDialog in the recreated activity. It seems like onProgressUpdate stops to being called in the rotated activity.
the relevant part of the code is shown below:
Worker Fragment
public class WorkerFragment extends Fragment {
Context mContext;
...
public static interface TaskCallbacks {
void onPreExecute();
void onProgressUpdate(int... progress);
void onPostExecute();
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mCallbacks = (TaskCallbacks) activity;
}
#Override
public void onDetach() {
super.onDetach();
mCallbacks = null;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Retain this fragment across configuration changes.
setRetainInstance(true);
}
//inner class
class DownloadFileFromURL extends AsyncTask<String, Int, Void> {
#Override
public void onPreExecute() {
if (mCallbacks != null) {
mCallbacks.onPreExecute();
}
#Override
public String doInBackground(String... f_url) {
... //some verifications of files
if(!localFile.exists()){
//http connection, check, buffer, inputstream, etc...
publishProgress((int)((bytesDownloaded*100)/remoteFileSize));
...
}
}
#Override
protected void onProgressUpdate(int... percent) {
if (mCallbacks != null) {
mCallbacks.onProgressUpdate(percent);
}
}
...
}
}
and the Activity
public class Updater extends Activity implements WorkerFragment.TaskCallbacks {
private WorkerFragment myWorker;
private ProgressDialog pDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_updater);
pDialog=null;
showDialog(1);
FragmentManager fm = getFragmentManager();
myWorker = (WorkerFragment) fm.findFragmentByTag("task");
if(myWorker == null)
{
myWorker = new WorkerFragment();
fm.beginTransaction().add(myWorker, "task").commit();
}
#Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 1:
pDialog = new ProgressDialog(this);
pDialog.setMessage("Baixando arquivos de mídia");
pDialog.setIndeterminate(false);
pDialog.setMax(100);
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.setCancelable(false);
pDialog.show();
dialogType=progress_bar_type;
return pDialog;
}
}
#Override
public void onProgressUpdate(int... progress) {
//setting progress percentage
if(pDialog!=null)
{
pDialog.setProgress(progress[0]);
}
}
#Override
public void onPostExecute(){
if(pDialog!=null)
{
dismissDialog(1);
...
}
}
Try to put this code in manifest, where you've indicated your activity
android:configChanges="orientation|screenSize"
In my app, I am getting text content from JSON and that content I am showing into text view. But, problem is text is not appearing complete and it is not formatted as well. I had checked my JSON using http://jsonformatter.curiousconcept.com/ and it showed the JSON is valid. I had printed the content that I received on the log and it is complete. Even, after setting it to textview and again getting back from it, I am getting complete data. But, it is not displaying complete text.
I am not getting where the problem is. The textview is inside scrollview.
Below is my code:
Base Activity
public class TIEBaseActivity extends MapActivity
{
//private ProgressDialog dialog;
public AlertDialog _alertDialog;
protected HeaderBar _headerBar;
protected FooterBar _footerBar;
protected LinearLayout _manager;
protected LinearLayout form;
protected TIEBaseActivity _self;
public void createDefaultView(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.basescreen);
this._self=this;
initView();
}
public void loadFormFromResource(int resourceID)
{
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(resourceID, null);
_manager.addView(view);
}
public void loadDefaultForm()
{
form=new LinearLayout(this);
form.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
form.setOrientation(LinearLayout.VERTICAL);
form.setGravity(Gravity.CENTER);
_manager.addView(form);
}
public void initView()
{
_headerBar = (HeaderBar) findViewById(R.id.baseHeaderBar);
_manager = (LinearLayout) findViewById(R.id.baseScrollContent);
//_footerBar = (FooterBar) findViewById(R.id.baseFooterBar);
_headerBar.view.setVisibility(View.GONE);
//_footerBar.view.setVisibility(View.GONE);
}
protected void showScreen(Intent intent) {
startActivity(intent);
}
public void setHeaderTitle(String title) {
if (_headerBar!=null) {
_headerBar.setTitle(title);
}
}
public Handler progressCloseHandler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (_alertDialog != null)
_alertDialog.cancel();
}
};
private Handler alertViewHandler = new Handler() {
public void handleMessage(Message msg) {
String message=(String)msg.obj;
AlertDialog.Builder _alert = new AlertDialog.Builder(TIEBaseActivity.this);
_alert.setMessage(message)
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
}
});
_alert.create().show();
}
};
public void DisplayAlert(String message) {
Message msg=Message.obtain(alertViewHandler);
msg.obj=message;
alertViewHandler.sendMessage(msg);
}
public void DisplayAlert(String message, int id) {
Message msg=Message.obtain(alertViewHandler);
msg.obj=message;
msg.what=id;
alertViewHandler.sendMessage(msg);
}
private Handler closeViewHandler=new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
_self.finish();
}
};
public void closeScreen() {
closeViewHandler.sendMessage(Message.obtain(closeViewHandler));
}
public void openRating()
{
Intent marketIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=com.dzo.tie"));
startActivity(marketIntent);
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
public void openShare()
{
String mMailSubject = "OIE App. - Get the All Indian Events happening in Overseas";
String mMailMessage = null;
mMailMessage = "Hi,\n I found this great Application. This application customize for Overseas Indian Events.";
mMailMessage += "\n";
mMailMessage += "Go to: https://market.android.com/details?id=com.dzo.oie";
mMailMessage += ",\n Please visit: http://www.dotzoo.net to see more about Dotzoo Inc.";
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/*");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, ""+mMailSubject);
emailIntent.putExtra(Intent.EXTRA_TEXT, mMailMessage);
startActivity(Intent.createChooser(emailIntent, "Share via..."));
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
Layout for BaseActivity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="#color/white"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/baseLayout">
<com.dzo.tie.ui.HeaderBar
android:id="#+id/baseHeaderBar"
android:layout_width="fill_parent"
android:layout_height="50dp"/>
<ScrollView
android:scrollbars="vertical"
android:fillViewport="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/baseScrollContent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center"
android:layout_width="fill_parent">
</LinearLayout>
</ScrollView>
I am extending this base activity in my activity class:
My Activity
public class TIEInfo extends TIEBaseActivity
{
TextView txtTieInfo;
String contents;
private String infoUrl = "http://www.tradeineu.com/tie_app/aboutTie.php";
protected void onCreate(Bundle savedInstanceState)
{
super.createDefaultView(savedInstanceState);
_headerBar.view.setVisibility(View.VISIBLE);
super.setHeaderTitle("Info");
init();
new TIEInfoAsyncTask(getParent(), infoUrl, txtTieInfo).execute();
}//onCreate
public void init()
{
loadFormFromResource(R.layout.tieinfo);
txtTieInfo = (TextView)findViewById(R.id.txtTieInfo);
}//init
}//TIEInfo
Layout for my activity
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/txtTieInfo"
android:textSize="12sp"
android:textColor="#color/copper_gold"
android:lineSpacingExtra="5dp"/>
You need to scroll to see the rest of your text.
Place your textview inside a scrollView and it will be ok.