how to display data in alert Box with splitview in android - android

package com.example.example2;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
public class MainActivity extends Activity {
WebView web1;
WebView web2;
Button btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final String str1 = "<html>This first Html data</html>";
final String str2 = "<br /><br />Read the handouts please for tomorrow.<br /><br /><!--homework help homework"
+ "help help with homework homework assignments elementary school high school middle school"
+ "// --><font color='#60c000' size='4'><strong>Please!</strong></font>"
+ "<img src='http://www.homeworknow.com/hwnow/upload/images/tn_star300.gif' />";
web1 = (WebView) findViewById(R.id.webfirst);
web2 = (WebView) findViewById(R.id.websecond);
btn = (Button) findViewById(R.id.compare);
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
web1.loadDataWithBaseURL("", str1, "text/html", "UTF-8", "");
web2.loadDataWithBaseURL("", str2, "text/html", "UTF-8", "");
// we have display This on Alert view with spliting .
}
});
}
}
This is my split view activity when i click on Button we are able to see data in web view with spliting activity But i have to do that when i click on Button then string 1 and string 2 should display in Pop window within same activity with splitted data how to split alert or pop view in android Please help me am unable to do this i have tired much But not getting how iw ill do it

Make your activity to dialog in manifest is the one way
<activity android:theme="#android:style/Theme.Dialog" />
by adding the above code in your activity you can see the activity as dialog
(OR)
Try to display custom dialog in this way
Dialog dialog_help = new Dialog(getActivity());
dialog_help.setContentView(R.layout.help_screen);
TextView tv_1 = (TextView) dialog_help.findViewById(R.id.tv_help_1);
tv_1.setText("");
dialog_help.setCancelable(true);
dialog_help.setTitle(" Help ");
dialog_help.setCanceledOnTouchOutside(true);
dialog_help.show();
dialog_help.getWindow().setGravity(Gravity.CENTER);
dialog_help.getWindow().setLayout(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);

Related

Cannot resolve symbol (any ID's) Android Studio

I'm a noob Android studio programmer (this is hour 2 of learning!) and I expect this is a real rookie error I'm making!
I've got a Plain Text field in my application and I would like to set the text of this dynamically. I've given the plain text field the ID of: "resultText". Here's what I try;
public void calcnums(View v)
{
int x=firstNum + seondNum;
resultText.setText("Result: " + x);
}
For some reason I get 'resultText' highlighted in red and the hover over message is; Cannot resolve symbol 'resultText'.
I have the feeling that I'm doing something wrong by using the ID, but I'm lost!
Full code as suggested in comments;
import android.app.Application;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import java.util.Random;
public class AddNumbers extends AppCompatActivity {
private int firstNum;
private int seondNum;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_numbers);
}
public void calcnums(View v)
{
int x=firstNum + seondNum;
resultText.setText(String.format("Result: %d", x);
}
public void setNums(View v)
{
TextView tx= (TextView) findViewById(R.id.text);
Random r = new Random();
int x=r.nextInt(2) + 1; // r.nextInt(2) returns either 0 or 1
firstNum = x;
r = new Random();
x=r.nextInt(2) + 1;
seondNum = x;
num1.setText(""+firstNum);
num2.setText(""+seondNum);
}
}
It seems you need to declare the View resultText
Like,
EditText resultText = (EditText) findViewById(R.id.resultText);
Also make sure that the name you are using for the resultText View in xml is written correctly as provided in the method findViewById()
usually cannot resolve symbol means some problems in variable declarations.
I am too learning android and I stumbled upon this problem as well.
I don't have the whole snippet of your code.But the thing you might be missing is to point your EditText object to view in xml.
EditText resultText = (EditText) v.findViewById(R.id.result_edit_text);
<EditText
android:id="#+id/result_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/result_edit_text"
/>
Let's assume that we have an layout with an edittext
<EditText
android:id="#id/txt_user_email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text" />
It has an ID. In your actitivy you must find and cast the EditText as follow:
EditText txtUserEmail = (EditText) findViewById(R.id.txt_user_email);
txtUserEmail.setText("klaus.dieter#lusty-swingers.de");
You need to find your text view in onCreate(), like that:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_numbers);
TextView tx= (TextView) findViewById(R.id.text);
}

Text viewed as HTML

Hey everyone this is a update from my previous question
https://stackoverflow.com/questions/6676440/android-showing-a-edittext-text-in-webview
I got the webview to see the text inside my Edit text field but its displaying it as text
this is the coding im using
case R.id.Preview:
Intent j = new Intent(this, Preview.class);
j.putExtra(com.afajje.htmlzero.Preview.URL,
myEditText.getText().toString());
startActivity(j);
}
return false;}
Want im trying to have it do is view the Edit text, text as HTML
For example if I put in the Edittext field
<html>
<head>
</head>
<body>
<p>This is a Preview</p>
</body>
</html>
In the web view itll just just the "This is a Preview"
Here ya go, a working demo:
package com.stackexchange.test;
import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.widget.EditText;
public class home extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText box = (EditText) findViewById(R.id.edittext);
String htmltext = "<b>This is bold. </ b> and <i> this is italic </ i>." ;
Spanned text = Html.fromHtml( htmltext );
box.setText( text );
}
}
You should see (except that I've edited the text in the app):
Try the below code to show the html text into the EditText.
String str = "<html><head></head><body><p>This is a Preview</p></body></html>";
editText = (EditText)findViewById(R.id.editText);
editText.setText(Html.fromHtml(str));
Well, in the editText, if you dont use "Html.fromHtml", the string will be display with the html tags. In a WebView, I really dont know what zou want to do...sorry

show the text of an EditText into a TextView

Describing the functionality of my application: I have put in a Relative Layout a TextView, an EditText and a button. All I am trying to do is: when the user writes something in the EditText and push the button, then the content of the EditText is appeared in the TextView(just like a chat-virtual chat). Everything works perfectly, but when the EditText is empty,and the button get pushed, an empty line is appeared in the TextView(and i don't want to..). Although I've tried to solve it using an if the empty line is still appearing in the TextView. I would be really greatfull, if you could help!!! Than you in advance!
Here is my code:
package teiath.android.appliacation;
import android.app.Activity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class M_chat extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/**Code for the scroll bars in the TextView. */
final TextView tv = (TextView)findViewById(R.id.TEXT_VIEW);
tv.setMovementMethod(new ScrollingMovementMethod());//for the scroll bars
/** Code for the scroll bars in the EditText. */
final EditText wr = (EditText)findViewById(R.id.EDIT_TEXT);
wr.setMovementMethod(new ScrollingMovementMethod());//for the scroll bars
final Button button = (Button) findViewById(R.id.btn1);//find the button by id in main.xml
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
String wrcontent = wr.getText().toString();//gets the text of the EditText and put it in "tvcontent" variable.
String tvcontent = tv.getText().toString();//gets the text of the textView and put it in "tvcontent" variable.
if (wrcontent!="")//if the EditText is not empty
{
//check if the TextView is empty or not
if (tvcontent!="")//If it is not empty...
{
tv.setText(tvcontent + "\n" + wrcontent);//add its current(TextView's text) text, new line and the text of the EditText as the new text of TextView.
//tv.setVisibility(0);//makes visible the textView with the cloud1.png background
wr.setText("");//set the text of the Edit Text as empty
//wrcontent = "";
}
else//if the TextView is empty...
{
tv.setText(wrcontent);//add the text of the editText as the new text of the TextView
wr.setText("");
}
}
/**if (wrcontent=="")
{
}*/
//finish();
}
});
}
}
Don't use !="" for String comparison. To check for empty text, use something like
if ( wrcontent != null && wrcontent.trim().length() == 0 ) {
Better yet, include Guava libraries in your code.

How the detect the "edittext" box whether it is nothing in Android?

I want to program a function that the toast exist when there is nothing
in the "edittext" box (id / password), but it dosen't work.
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.content.Intent;
import android.widget.EditText;
import android.widget.Toast;
import android.view.View.OnClickListener;
import android.text.Editable;
public class Test extends Activity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button1 = (Button) findViewById(R.id.button1);
EditText id = (EditText) findViewById(R.id.id);
EditText pwd = (EditText) findViewById(R.id.pwd);
Editable Str_id;
Editable Str_pwd;
Str_id = id.getText();
Str_pwd = pwd.getText();
button1.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v){
if(Str_id==null || Str_pwd == null){
Toast.makeText(Test.this, "Please Enter User ID / Password", Toast.LENGTH_LONG).show();
}
});
}
}
move the following lines inside onClick and try:
Str_id = id.getText();
Str_pwd = pwd.getText();
EDIT: Move
Editable Str_id;
Editable Str_pwd;
Str_id = id.getText();
Str_pwd = pwd.getText();
inside onClick().
I do not recommend toasting a message that a field is required. You're better off just giving the EditText focus, this focus tells the user that this field is required. Its less information on the screen and its subtle, which is important. You don't want to disturb the user too much.
The idea is...
When the submit button is clicked, check the EditTexts if any of them are empty, notify the user through requesting focus, also make sure your UI tells them before hand that the fields required. The hint of the EditText works well for this.

In an Android TextView, is it possible to insert paragraphs?

Below is an example of the type of problem that I have. I have data in a pojo that I need to display in a textview... the data has pseudo code that denotes each paragraph with [p]
I would like to somehow parse the [p]'s into paragraphs when they are displayed in the textview. Can this be done? Is there something I can substitute for the [p] that will make a new paragraph in the textview?
Question question = new Question();
question.setText("Here is the first paragraph.[p] And this should be the second.");
TextView view = (TextView) findViewById(R.id.qtext);
view.setText(question.getParsedText());
Hi i would parse the whole String and then replace every [p] with \n or even \n\n as you like.
\n in the String makes a linebreak. For example use it like that:
question.setText("Here is the first paragraph.\n\n And this should be the second.");`
The method which can do that easily is String.replace(...)
You can also try this
String summary = "<html><font color=\"#FFFFFF\"" +
"<p align="+ "\"" +"left" + "\""+ ">" + "MY data" +"</p>"+
"</font></html>";
mTextView.setText(Html.fromHtml(summary));
TextView tw = findViewById(R.id.t);
tw.setText("first line\nsecond line\nthird line");
<br> and <p> work if you need other formatting like bold and are in the middle of an Html.fromHtml:
import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.widget.TextView;
public class Main extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final TextView tv = new TextView(this);
tv.setText(Html.fromHtml("first<br><b>second</b>"));
setContentView(tv);
}
}
Tested on Android 22.

Categories

Resources