Not saying it should, it is my first after all, but I'm trying and so far 
there's been some progress here and there but tying it all together now 
isn't working out right. I'm new to Java as well so I'm sure the problems 
are related to my poor skills writing java code at this point. Please don't 
be offended by my code below. I know it's bad and shames even the newest 
programmer. I do take feedback well and any and all improvements will be 
greatly appreciated.

GOAL (SHORT): OnClick Button appends own getText to TextView/OnClick Call 
Button invokes ACTION_CALL

GOAL (LONG): The app is a simple dialer app the user uses to dial a 
destination number (most often an international number) and then the app 
uses ACTION_CALL to call a routing number, passing it the destination 
number the user entered. I assumed this would be relatively simple since 
the app actually has very little work to do. The authorization and account 
details are handled by our server and has been using the phone number for 
years as the auth source. So the app just needs to place the call to the 
access number and the user will be authenticated on the server based on 
their phone number. So calling is all there is to it. (At least I think 
so...) ;)

So my dialer app is suffering from user-headspace issues where the buttons 
won't update the Text View field in order to enter a valid phone number. In 
the layout I have the TextView and the EditText, as well as all the buttons 
with IDs. In the class I set up some cases where the button is pressed, it 
gets the text from the TextView, and sets the text of the TextView to the 
getText + button.getText. (You'll see in the code below) but the button's 
actually do nothing. Also, the button set to the ACTION_CALL intent does 
nothing as well.

I have the permission and intents set in the manifest but I will post that 
if anyone suspects my problem might lie in that file. Here is the code for 
the layout, activity_main.xml:

<pre><?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
    android:id="@+id/mainlayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/title_two"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:maxLength="15" >
        <requestFocus />
    </EditText>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent" >
        <Button
            android:id="@+id/oneButton"
            android:layout_width="93dp"
            android:layout_height="wrap_content"
            android:text="1" />
        <Button
            android:id="@+id/twoButton"
            android:layout_width="93dp"
            android:layout_height="wrap_content"
            android:text="2" />
        <Button
            android:id="@+id/threeButton"
            android:layout_width="93dp"
            android:layout_height="wrap_content"
            android:text="3" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent" >
        <Button
            android:id="@+id/fourButton"
            android:layout_width="93dp"
            android:layout_height="wrap_content"
            android:text="4" />
        <Button
            android:id="@+id/fiveButton"
            android:layout_width="93dp"
            android:layout_height="wrap_content"
            android:text="5" />
        <Button
            android:id="@+id/sixButton"
            android:layout_width="93dp"
            android:layout_height="wrap_content"
            android:text="6" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent" >
        <Button
            android:id="@+id/sevenButton"
            android:layout_width="93dp"
            android:layout_height="wrap_content"
            android:text="7" />
        <Button
            android:id="@+id/eightButton"
            android:layout_width="93dp"
            android:layout_height="wrap_content"
            android:text="8" />
        <Button
            android:id="@+id/nineButton"
            android:layout_width="93dp"
            android:layout_height="wrap_content"
            android:text="9" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent" >
        <Button
            android:id="@+id/starButton"
            android:layout_width="93dp"
            android:layout_height="wrap_content"
            android:text="*" />
        <Button
            android:id="@+id/zeroButton"
            android:layout_width="93dp"
            android:layout_height="wrap_content"
            android:text="0" />
        <Button
            android:id="@+id/poundButton"
            android:layout_width="93dp"
            android:layout_height="wrap_content"
            android:text="#" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent" >
        <Button
            android:id="@+id/callButton"
            android:layout_width="93dp"
            android:layout_height="wrap_content"
            android:text="Call" />
        <Button
            android:id="@+id/contactsButton"
            android:layout_width="93dp"
            android:layout_height="wrap_content"
            android:text="Con" />
        <Button
            android:id="@+id/deleteButton"
            android:layout_width="93dp"
            android:layout_height="wrap_content"
            android:text="Del" />
    </LinearLayout>

</LinearLayout></pre>


And then MainActivity.java:

<pre>package com.example.dialerTest;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity implements OnClickListener {
    EditText numTxt;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button oneButton = (Button)findViewById(R.id.oneButton);
        oneButton.setOnClickListener(this);
        Button twoButton = (Button)findViewById(R.id.twoButton);
        twoButton.setOnClickListener(this);
        Button threeButton = (Button)findViewById(R.id.threeButton);
        threeButton.setOnClickListener(this);
        Button fourButton = (Button)findViewById(R.id.fourButton);
        fourButton.setOnClickListener(this);
        Button fiveButton = (Button)findViewById(R.id.fiveButton);
        fiveButton.setOnClickListener(this);
        Button sixButton = (Button)findViewById(R.id.sixButton);
        sixButton.setOnClickListener(this);
        Button sevenButton = (Button)findViewById(R.id.sevenButton);
        sevenButton.setOnClickListener(this);
        Button eightButton = (Button)findViewById(R.id.eightButton);
        eightButton.setOnClickListener(this);
        Button nineButton = (Button)findViewById(R.id.nineButton);
        nineButton.setOnClickListener(this);
        Button starButton = (Button)findViewById(R.id.starButton);
        starButton.setOnClickListener(this);
        Button zeroButton = (Button)findViewById(R.id.zeroButton);
        zeroButton.setOnClickListener(this);
        Button poundButton = (Button)findViewById(R.id.poundButton);
        poundButton.setOnClickListener(this);
        Button callButton = (Button)findViewById(R.id.callButton);
        callButton.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) {
                startActivity(new Intent(Intent.ACTION_CALL, 
Uri.parse("tel:" + numTxt.getText())));
            }
        });

        numTxt = (EditText) findViewById(R.id.editText1);
    }
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.oneButton:
            numTxt.setText(numTxt.getText().toString() + " " + "1");
        break;
        case R.id.twoButton:
            numTxt.setText(numTxt.getText().toString() + " " + "2");
        break;
        case R.id.threeButton:
            numTxt.setText(numTxt.getText().toString() + " " + "3");
        break;
        case R.id.fourButton:
            numTxt.setText(numTxt.getText().toString() + " " + "4");
        break;
        case R.id.fiveButton:
            numTxt.setText(numTxt.getText().toString() + " " + "5");
        break;
        case R.id.sixButton:
            numTxt.setText(numTxt.getText().toString() + " " + "6");
        break;
        case R.id.sevenButton:
            numTxt.setText(numTxt.getText().toString() + " " + "7");
        break;
        case R.id.eightButton:
            numTxt.setText(numTxt.getText().toString() + " " + "8");
        break;
        case R.id.nineButton:
            numTxt.setText(numTxt.getText().toString() + " " + "9");
        break;
        case R.id.starButton:
            numTxt.setText(numTxt.getText().toString() + " " + "*");
        break;
        case R.id.zeroButton:
            numTxt.setText(numTxt.getText().toString() + " " + "0");
        break;
        case R.id.poundButton:
            numTxt.setText(numTxt.getText().toString() + " " + "#");
        break;
        }
    }
}</pre>

Thanks for any advice or solutions you can offer. As it is, I've been 
looking for several days and can't find anything that helps. Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to