Stop reload () after a certain scroll - java

With this code, as I while scrolling, say 10%, disable web.reload (); And for one, as I variable String url of shouldOverrideUrlLoading endure beyond the example as above in a variable String XYvariable.
package ru.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends AppCompatActivity {
TextView TEXT;
String XYvariable;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WebView web = (WebView) findViewById(R.id.webView);
web.loadUrl("http://example.com/string.html");
web.getSettings().setJavaScriptEnabled(true);
new Timer().schedule(new TimerTask() {
#Override
public void run() {
// TODO Auto-generated method stub
web.reload();
}
}, 1000, 1000);
web.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
String Cur = (String) url.substring(23);
String Link = (String) url.substring(16,23);
String XY = (String) url; // Post varriable up in string XYvariable
setContentView(R.layout.vot);
TEXT = (TextView) findViewById(R.id.textView);
switch (Link){
case "id_user":
TEXT.setText(Cur+" / user");
break;
case "id_mess":
TEXT.setText(Cur + " / messages");
break;
}
return true;
}
});
}
public boolean onCreateOptionsMenu (Menu menu){
getMenuInflater().inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<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="ru.MainActivity">
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/webView"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
In advance thank you all, very much! ))

Related

Go to full image screen

I have made an android app to display image from firebase into recycler view and when user click a image it has to go to its full screen page and have tried a several times but it just shows the blank activity
You can use PhotoView library (com.github.chrisbanes.photoview) to show full screen picture as below:
Piccaso is used here to show images, but you can use other image libraries such as Fresco, Glide .
ActivityLargeImageView
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.Window;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.github.chrisbanes.photoview.PhotoView;
import com.github.chrisbanes.photoview.PhotoViewAttacher;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import java.io.File;
import butterknife.BindView;
import butterknife.ButterKnife;
public class ActivityLargeImageView extends FragmentActivity {
#BindView(R.id.photoview_image)
PhotoView photoviewImage;
#BindView(R.id.progressbar)
ProgressBar progressBar;
File mFile;
PhotoViewAttacher mAttacher;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_large_image_view);
ButterKnife.bind(this);
progressBar.setVisibility(View.VISIBLE);
String img_url = getIntent().getExtras().getString("image_url");
try {
mFile = new File(img_url);
} catch (Exception ex) {
}
if (mFile.exists()) {
Picasso.with(getApplicationContext()).load(mFile).into(photoviewImage, imageLoadedCallback);
} else {
Picasso.with(getApplicationContext()).load(img_url).into(photoviewImage, imageLoadedCallback);
}
}
Callback imageLoadedCallback = new Callback() {
#Override
public void onSuccess() {
if (mAttacher != null) {
mAttacher.update();
} else {
mAttacher = new PhotoViewAttacher(photoviewImage);
}
progressBar.setVisibility(View.GONE);
}
#Override
public void onError() {
Toast.makeText(getApplicationContext(), getResources().getString(R.string.error_message_connection_to_server), Toast.LENGTH_LONG).show();
}
};
}
XML File
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:background="#000000"
android:orientation="vertical" >
<com.github.chrisbanes.photoview.PhotoView
android:id="#+id/photoview_image"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="#+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>

Android Spinner on activity other than starting activity

I'm having a bit of an issue, I'm working on a android app that requires a spinner to update a string to your spinner selection, I have it all working and everything, the problem is that I need the spinner on another activity than the starting activity but when I start the app with a different activity than the one with the spinner and activate the array adapter and listener at the same time I switch views to the one with the spinner, the spinner is empty with no choices. I can't for the life of me figure this out. PS, sorry about the weird variable names I get bored and instead of making a proper name I think of something on the spot and come back and change it later. PPS The name of the content view with the spinner is orderpage and the one I want to have start with the app is activity_main PPPS I cut out some methods I deemed irrelevant so there are some variables not used. I attached my code below:
package com.NIQUOLI.Deliveryapp;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import com.NIQUOLI.Deliveryapp.GMailSender;
import android.R.string;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Debug;
import android.os.StrictMode;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
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.EditText;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends Activity {
public static boolean deeznuts = false;
public static String storenamestring;
public static String namesame;
public static String instructionsame;
public int choice = 0;
private Spinner spinner1;
private Button button = null;
String[] stores;
Spinner sp;
public void cont(View View){
deeznuts = true;
setContentView(R.layout.orderpage);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.orderpage);
button = (Button) findViewById(R.id.send_email);
super.onCreate(savedInstanceState);
sp = (Spinner) findViewById(R.id.sp);
stores = getResources().getStringArray(R.array.stores);
if (deeznuts = true){
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,stores);
sp.setAdapter(adapter);
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
int index = arg0.getSelectedItemPosition();
Toast.makeText(getBaseContext(), "You selected"+stores[index], Toast.LENGTH_LONG).show();
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
}
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
parent.getItemAtPosition(pos);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
and of course my XML with the s[ommer:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context="com.NIQUOLI.Deliveryapp.SendMailTask" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="#string/order_page"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:gravity="center_horizontal"
android:hint="#string/enter_your_name"
android:inputType="text" >
<requestFocus />
</EditText>
<Spinner
android:id="#+id/sp"
android:layout_width="388dp"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/instructions"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.34"
android:ems="10"
android:inputType="textMultiLine" />
<Button
android:id="#+id/send_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="#string/send_order" />
</LinearLayout>
On the 6th line of the onCreate method in the first code sample, if(deeznuts = true) should be if(deeznuts == true).

Parse Html from website with android studio, Java

I am making this question today because I can not find certain information on google and/or Stack Overflow. My Problem is, I am creating a Android Application and I want certain information from a Website. So I use Jsoup as my parse Library. I follow all the instruction and set The data in the Text to Show up with The HTML text. For Some reason it is either a network connection or my code is wrong in communicating with the website? I do not know what is up with the app. I am Using Android Studio, so when running either the emulator or on a device it will just not pull html from the website.
Here is My code for 2 Classes. This has to be in Java.
package update.app.jdog1218.com.messingaround;
import android.app.Activity;
import android.app.DialogFragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.net.URL;
import java.net.URLConnection;
public class MainActivity extends Activity {
private Button answer_Button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout bible = new RelativeLayout(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
return super.onOptionsItemSelected(item);
}
public void gotoInbeddedBible(MenuItem item) {
Intent bibleclass = new Intent(this, bible.class);
final int result = 1;
bibleclass.putExtra("callingActivity", "MainActivity");
startActivity(bibleclass);
startActivityForResult(bibleclass, result);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
public void exit(MenuItem item) {
Button exitProcess = (Button) findViewById(R.id.submit);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
public void sotd(MenuItem item) {
Intent clickedSotd = new Intent(this, Sotd.class);
int result = 1;
startActivity(clickedSotd);
}
}
This is the class I want to use Jsoup in.
package update.app.jdog1218.com.messingaround;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.Menu;
import android.widget.TextView;
import org.jsoup.Jsoup;
import org.jsoup.Connection;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.w3c.dom.Node;
import org.w3c.dom.Text;
import java.io.IOException;
import static org.jsoup.Jsoup.*;
/*
* Created by Joel on 5/28/2015.
*/
public class Sotd extends Activity {
#Override
protected void onStart() {
super.onStart();
}
String title;
#Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.sotd);
Intent activityThatCalled = getIntent();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu);
}
/**
* Pull and Parse the HTML of Compass HB for SOTD.
*
* #return DocumentString
* #throws IOException
*/
protected String pullHTML() {
super.onStart();
final String url = "https://www.compasshb.com/api/v1/passages";
Document doc = null;
TextView textView = (TextView) findViewById(R.id.SOTD);
try {
doc = Jsoup.connect(url).get();
textView.setText(doc.ownText());
String paragraph = doc.title();
return paragraph;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostResume() {
super.onPostResume();
}
}
This is the XML File for the Layout I want to output too.
<LinearLayout 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"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:weightSum="1"
android:background="#drawable/the_rendered_background">
<TextView
android:text="#string/text_of_activity_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:height="40dp"
android:capitalize="none"
android:width="200dp"
android:textColor="#000000"
android:id="#+id/text_view" />
</LinearLayout>
SOTD is where I want it to output too.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".Sotd"
android:weightSum="1"
android:background="#drawable/the_rendered_background"
android:backgroundTintMode="add">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/SOTD"
/>
</LinearLayout>
Pretty Much I just need someone to tell me what I am doing wrong./Review

I am working on a basic toDo app. When I long press on the item it should be deleted from my list but it does nothing. What am i doing wrong?

I am trying to add and delete items in my todo list. It adds the items fine but I have set up a onLongClickListener for deleting the items and it does nothing. I am a beginner so I may have missed something. Please help me out. Any help is appreciated.
package com.example.todolist;
import java.util.ArrayList;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.os.Build;
import android.app.ListActivity;
public class MainActivity extends Activity implements OnClickListener{
private ArrayList<String> items;
private ArrayAdapter <String> adapter;
private EditText ptadd;
private Button badd;
private ListView lvTodo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initialize();
items = new ArrayList <String>();
adapter = new ArrayAdapter<String>(this,adroid.R.layout.simple_list_item_1, items);
lvTodo.setAdapter(adapter);
setListViewListener();
}
private void setListViewListener(){
lvTodo.setOnItemLongClickListener(new OnItemLongClickListener (){
#Override
public boolean onItemLongClick(AdapterView<?> vadapter, View item,
int position, long id) {
// TODO Auto-generated method stub
items.remove(position);
adapter.notifyDataSetChanged();
return true;
}
});;
}
private void initialize() {
// TODO Auto-generated method stub
ptadd = (EditText) findViewById(R.id.etadd);
lvTodo = (ListView) findViewById(R.id.lvTodo);
badd = (Button) findViewById(R.id.badd);
badd.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
String lv = ptadd.getText().toString();
adapter.add(lv);
ptadd.setText("");
}
}
my XML file:
<RelativeLayout 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"
android:weightSum="100"
>
<ListView
android:id="#+id/lvTodo"
android:layout_width="293sp"
android:layout_height="250sp" >
</ListView>
<EditText
android:id="#+id/etadd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/button1"
android:layout_weight="70"
android:ems="10"
/>
<Button
android:id="#+id/badd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="30"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Add"
/>
</RelativeLayout>
In the code you posted, you're never calling setListViewListener. Call the method in initialize
private void initialize() {
// TODO Auto-generated method stub
ptadd = (EditText) findViewById(R.id.etadd);
lvTodo = (ListView) findViewById(R.id.lvTodo);
badd = (Button) findViewById(R.id.badd);
badd.setOnClickListener(this);
//Missing this
setListViewListener();
}

Application stopped working when loading layout with setContentView

Here's the XML layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/search_lyt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:name="search_act"
tools:context="com.example.app.Hisp$PlaceholderFragment">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:src="#drawable/hispania_lgs"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:id="#+id/back2"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Info"
android:id="#+id/info2"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/model_list"
android:layout_below="#+id/textViewML"
android:layout_alignParentRight="true"
android:layout_above="#+id/back2"
android:choiceMode="singleChoice" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Select any of the models below and press Info for the model's specifications"
android:id="#+id/textViewML"
android:layout_below="#+id/imageView2"
android:layout_alignLeft="#+id/model_list" />
And using the setContentView method results in an 'Application stopped working'.
setContentView(R.layout.search_hisp);
Any idea on how to fix this? I'm quite new to Android Development and still trying to find how to switch layouts the correct way.
Well, even I change the onCreate()' setContentView to R.layout.search_hisp and gave me the error on startup. So my guess is it's probably from the XML file or something.
Thanks in advance!
Edit, there's the error:
>
03-25 12:10:23.415 20858-20858/com.example.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
at com.example.app.Hisp.beginSearch(Hisp.java:121)
at com.example.app.Hisp$3.onClick(Hisp.java:107)
at android.view.View.performClick(View.java:4231)
at android.view.View$PerformClick.run(View.java:17537)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:5751)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
at dalvik.system.NativeStart.main(Native Method)
03-25 12:10:23.420 515-550/? E/EmbeddedLogger﹕ App crashed! Process: com.example.app
03-25 12:10:23.420 515-550/? E/EmbeddedLogger﹕ App crashed! Package: com.example.app v1 (1.0)
03-25 12:10:23.420 515-550/? E/EmbeddedLogger﹕ Application Label: Hisp_Selector
And here's the code:
package com.example.app;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.DataSetObserver;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.UserHandle;
import android.preference.DialogPreference;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View.OnClickListener;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.view.ViewGroup;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.Window;
import android.view.WindowManager;
import android.os.Build;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ListAdapter;
import android.widget.ListView;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import android.widget.LinearLayout;
public class Hisp extends ActionBarActivity {
public static ActionBarActivity activity;
Context ctx;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
activity = this;
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_hisp);
TextView txt = (TextView) findViewById(R.id.textViewML);
Button btn = (Button) g(R.id.search);
Button rst = (Button) g(R.id.reset);
rst.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
finish();
startActivity(getIntent());
}
});
OnClickListener _rdb = new OnClickListener() {
#Override
public void onClick(View view) {
((CheckBox) g(R.id.R134a)).setChecked(false);
((CheckBox) g(R.id.R22)).setChecked(false);
((CheckBox) g(R.id.R404A)).setChecked(false);
((CheckBox) g(R.id.R507A)).setChecked(false);
((CheckBox) view).setChecked(true);
}
};
((CheckBox) g(R.id.R134a)).setOnClickListener(_rdb);
((CheckBox) g(R.id.R22)).setOnClickListener(_rdb);
((CheckBox) g(R.id.R404A)).setOnClickListener(_rdb);
((CheckBox) g(R.id.R507A)).setOnClickListener(_rdb);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
beginSearch();
}
});
/*
if (stanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
*/
}
public void beginSearch() {
((EditText) g(R.id.rh)).setText("Test##".toCharArray(), 0, "Test##".length());
Boolean err = false;
try {
if (!(Double.parseDouble((((EditText) g(R.id.capacity)).getText().toString().trim())) >= 0 &&
isBetween(-35, 5, Integer.parseInt(((EditText) g(R.id.evaptemp)).getText().toString().trim())) &&
isBetween(28, 58, Integer.parseInt(((EditText) g(R.id.condtemp)).getText().toString().trim())) &&
isBetween(5, 13, Integer.parseInt(((EditText) g(R.id.dt1)).getText().toString().trim()))
)) err = true;
} catch(Exception e) {
err = true;
}
if (err) {
showMessageBox("ERROR", "Make sure you have filled all the fields correctly.", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
} else {
setContentView(R.layout.search_hisp);
}
}
public View g(int id) {
return activity.findViewById(id);
}
public Boolean isBetween(Integer i1, Integer i2, Integer ix) {
if (ix >= i1 && ix <= i2) return true;
return false;
}
public void showMessageBox(Object ttl, Object msg, DialogInterface.OnClickListener rt) {
new AlertDialog.Builder(activity)
.setMessage(msg.toString())
.setTitle(ttl.toString())
.setCancelable(false)
.setNeutralButton(android.R.string.ok, rt)
.show();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.hisp, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_hisp, container, false);
return rootView;
}
}
}
Because in onCreate() you have used
EditText textViewML = (EditText) findViewById(R.id.textViewML);
instead of
TextView txt = (TextView) findViewById(R.id.textViewML);
so you got problem. So you need to use after your setContentView() method.
TextView txt = (TextView) findViewById(R.id.textViewML);
Put in the onCreate :
TextView textViewML = (TextView) findViewById(R.id.textViewML);
The error was from
((EditText) g(R.id.rh)).setText("Test##".toCharArray(), 0, "Test##".length());
Thanks a lot guys for pointing this out!
you are casting Textview to EditText dont do that
EditText textViewML = (EditText) findViewById(R.id.textViewML);
change it as
TextView textViewML = (TextView) findViewById(R.id.textViewML);
Exception is not your layout file it is in your java file you are casting TextView into EditText.
You can not Cast Super class in to sub class.
you can cast Sub class into Super Class.
You can Cast EditText into TextView but not TextView in to EditText.
Change this line
TextView txt = (TextView) findViewById(R.id.textViewML);
Thanx

Categories

Resources