Can i display the CallLog numbers in my edittext? New here - android

I have created a simple xml with one button and one edittext.
Upon clicking the button, i can get into the CallLog page.
Is it possible to display the selected numbers into my EditText, after i click on any numbers in my CallLog??
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="true"
android:orientation="horizontal" >
<EditText
android:id="#+id/edittext"
android:layout_width="172dp"
android:layout_height="wrap_content"
android:layout_weight="0.29"
android:hint="CONTACT NUMBER" >
<requestFocus />
</EditText>
<Button
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CALL LOG" />
</LinearLayout>
Coding:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class CallLogRetrieveActivity extends Activity {
Button myCallLogBtn;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myCallLogBtn=(Button)findViewById(R.id.btn);
myCallLogBtn.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
Intent myIntent=new Intent();
myIntent.setAction(Intent.ACTION_CALL_BUTTON);
startActivity(myIntent);
}});
}
}

You should start reading manual and tutorial first, not asking here about elementary things that you'd simply know after doing RTFM. So "yes, you can". But now please do your homework, by reading "android call log tutorial" googled materials. Nobody here is going that for you.

Related

Keep user in Activity

I was creating an app then a question come out:
how can i keep user in activity?
I've put two editTexts with input of int.
i want user be kept in activity until he/she puts valid numbers in edittexts.
any ideas?
The solution is very simple all you need to do is get the string values from the edit text box and have a condition in your setonclicklistener that checks the strings if they match to a certain value, if yes the intent from current activity will take you to next if not it will show an error on the edit text box (by using .setError()) and return.
Here is the Java Class Code:
package com.example.text_to_speech;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;
public class ActivityA extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity);
EditText editText1,editText2;
Button button;
editText1=findViewById(R.id.ed1);
editText2=findViewById(R.id.ed2);
button=findViewById(R.id.check_input);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(!editText1.getText().toString().equals("Don"))
{
Toast.makeText(ActivityA.this, "You Can't Leave this Activity, Input Correct Fields", Toast.LENGTH_SHORT).show();
editText1.setError("Input Correct values");
return;
}
if(!editText1.getText().toString().equals("Tom"))
{
Toast.makeText(ActivityA.this, "You Can't Leave this Activity, Input Correct Fields", Toast.LENGTH_SHORT).show();
editText2.setError("Input Correct values");
return;
}
Intent intent=new Intent(ActivityA.this,MainActivity.class);
startActivity(intent);
}
});
}
}
XML Code:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ActivityA">
<EditText
android:layout_margin="10dp"
android:id="#+id/ed1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:hint="Input Data Here"
android:textColor="#000000"
android:textSize="20sp" />
<EditText
android:layout_margin="10dp"
android:layout_below="#id/ed1"
android:id="#+id/ed2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:hint="Input Data Here"
android:textColor="#000000"
android:textSize="20sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/ed2"
android:id="#+id/check_input"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="20dp"
android:text="Go to Next Activity"
/>
</RelativeLayout>
Output:

How to make a texField open with click of a button?

I am new to android programming and there are a few things I don't quite know how to do yet. I am doing a course on udemy and was trying to put together everything I have learned up to a certain point.
What I am trying to do is have the user click on a button (i have 12) and have it bring up a textField where they can enter two numbers. I just want to be able to get the user's two numbers and i'm pretty sure I can figure out the rest ( I hope). I just don't understand how to go about doing this.
Any help would be much appreciated. Basically all I want to do is to be able to have the user click on one of the 12 buttons and be asked to enter two values, then take those values and perform a calculation on it.
Your xml could be like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/b_ok"
android:text="Click Me"/>
<EditText android:layout_width="fill_parent"
android:layout_height="match_parent"
android:visibility="invisible"
android:id="#+id/et_showme"/>
</LinearLayout>
and your activity could be like this:
package com.william.kinaan.welcomeback;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class Test1 extends Activity implements OnClickListener {
private Button b_ok;
private EditText et_showme;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test1);
initialize();
}
private void initialize() {
this.b_ok = (Button) findViewById(R.id.b_ok);
this.b_ok.setOnClickListener(this);
this.et_showme = (EditText) findViewById(R.id.et_showme);
}
#Override
public void onClick(View v) {
this.et_showme.setVisibility(View.VISIBLE);
}
}
Create an Activity that has 2 EditTexts
When user click a button the Activity is started and user can enter the Numbers
Try this.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_id"
android:visibility="invisible"
android:text="sample text"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click"
android:id="#+id/click"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
And in your activity, you can do like this.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
Button button = (Button) findViewById(R.id.click);
final EditText text = (EditText) findViewById(R.id.tv_id);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
text.setVisibility(View.VISIBLE);
}
});
}

Android project display error on R.id.button

I surdenly noticed that My project starts throwing error anytime I try to access a resources that is a button. It underlines R.id.button. I dont understand why. I even deleted the last xml that I created but problem persist.
This is an example of my xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/layoutborder"
android:orientation="vertical" >
<TextView
android:id="#+id/chat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/stepone"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/wine" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:src="#drawable/ai" />
<Button
android:id="#+id/drugdetails"
style="#style/smallButtonStyleBlackpearl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:text="#string/nextbut" />
</LinearLayout>
My Java code
package com.example.rhemahealthcare;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.actionbarsherlock.app.SherlockActivity;
import com.example.rhemahealthcare.R;
public class SteponeActivity extends SherlockActivity{
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.steponeactivity);
final Button button = (Button)findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
// TODO Auto-generated method stub
Intent intent = new Intent(SteponeActivity.this,SteptwoActivity.class);
startActivity(intent);
}
});
}
}
i think you change any button1 id buy clicking right click and choose edit id. this option changes all the ids with that name in all the layouts.
As #Aleks G gussed it right in the comment, you don't have any button with id as button1 in your xml file. You've mentioned it :
final Button button = (Button)findViewById(R.id.button1);
Use the appropriate ID or put one in your layout file.
I have figured out the problem. My button ids were automatically change to button1 so they did not reference their previous ids that I gave to them. Thanks alot

(Eclipse) Android force close

This is the java code and xml file for a program I am writing, and it force closes whenever i try to invoke the plusCalc button in-program. Could someone please tell me why?
Thank you!
Java file:
package org.example.knittingframe;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.content.Intent;
public class KnittingFrame extends Activity implements OnClickListener {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View plusCalc = findViewById(R.id.plus_calc_button);
plusCalc.setOnClickListener(this);
View exitbutton = findViewById(R.id.exit_button);
exitbutton.setOnClickListener(this);
}
public void onClick(View v) {
switch(v.getId()) {
case R.id.plus_calc_button:
startPlusCalc();
break;
case R.id.exit_button:
finish();
break;
}
}
public void startPlusCalc() {
Intent i = new Intent(this, PlusCalc.class);
startActivity(i);
}
}
Here is the XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="#string/main_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="25dip"
android:textSize="24.5sp" />
<Button
android:id="#+id/plus_calc_button"
android:layout_width="300px"
android:layout_height="wrap_content"
android:text="#string/plusCalc_label"
android:layout_gravity="center" />
<Button
android:id="#+id/exit_button"
android:layout_width="300px"
android:layout_height="wrap_content"
android:text="Exit"
android:layout_gravity="center" />
</LinearLayout>
Without the stack trace it appears that the problem is with declaring the PlusCalc.class class in the App Manifest file, because as you say, the error only appears when you click on the PlusCalc button.
If this doesn't help please post the stack trace.

Runtime Android exception after pressing a button to go to next Activity

I have this code:
package com.problemio;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class ProblemioActivity extends Activity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button addProblemButton = (Button)findViewById(R.id.add_problem_button);
Button browseProblemsButton = (Button)findViewById(R.id.browse_problems_button);
Button searchProblemsButton = (Button)findViewById(R.id.search_problems_button);
Button myProblemsButton = (Button)findViewById(R.id.my_problems_button);
addProblemButton.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v) {
Intent myIntent = new Intent(ProblemioActivity.this, AddProblemActivity.class);
ProblemioActivity.this.startActivity(myIntent);
}
});
}
}
It compiles fine and displays the addProblemButton button, but when that button is clicked, the system gives a runtime exception.
Here is the AddProblemActivity class:
package com.problemio;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class AddProblemActivity extends Activity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//TextView text = (TextView) dialog.findViewById(R.id.addProblemText);
//text.setText(R.string.addProblemText);
TextView tv = new TextView(this);
tv.setText("Please Add a Problem");
setContentView(tv);
}
}
and here is the layout main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="First, add the problem you want to solve!"
/>
<TextView
android:id="#+id/add_problem_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add a Problem You Want To See Solved"
/>
<Button
android:id="#+id/add_problem_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add a Problem"
/>
<Button
android:id="#+id/browse_problems_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Browse Problems"
/>
<Button
android:id="#+id/search_problems_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Search Problems"
/>
<Button
android:id="#+id/my_problems_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="View My Problems"
/>
</LinearLayout>
any idea what might be going wrong? By the way, I can't seem to locate the stack trace of the exception. Where should I look for that in Eclipse? All it currently shows me is AndroidRuntimeException - dalvik.system.NativeStart.main
Thanks!!
The only problem I can think of is that your Activity "AddProblemActivity" is not register in the manifest.
See the logs under LogCat...you will find it in Window >Show View >Android > LogCat

Categories

Resources