Thursday, April 24, 2014

Unfortunately, app name has stopped.


This error message is displayed in logcat.
Here are the java source files
package com.example.dialer;


import android.os.Bundle;
import android.R.string;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.text.Selection;
import android.text.Spannable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;

public class MainActivity extends Activity {

private EditText et;
private Button btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9;
private Button btn11, btn12;
private LinearLayout llMainView;
private View mView;
private StringBuffer input;
private int length;

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

InitView ();
}

private void InitView ()
{
et = (EditText) findViewById (R.id.tv1);
btn0 = (Button) mView.findViewById (R.id.btn0);
btn1 = (Button) mView.findViewById (R.id.btn1);
btn2 = (Button) mView.findViewById (R.id.btn2);
btn3 = (Button) mView.findViewById (R.id.btn3);
btn4 = (Button) mView.findViewById (R.id.btn4);
btn5 = (Button) mView.findViewById (R.id.btn5);
btn6 = (Button) mView.findViewById (R.id.btn6);
btn7 = (Button) mView.findViewById (R.id.btn7);
btn8 = (Button) mView.findViewById (R.id.btn8);
btn9 = (Button) mView.findViewById (R.id.btn9);
/ / Number of special keys
btn11 = (Button) mView.findViewById (R.id.btn11) ;/ / color
btn12 = (Button) mView.findViewById (R.id.btn12) ;/ / delete
}


public void onClick (View v)
{
switch (v.getId ())
{
case R.id.btn1:
case R.id.btn2:
case R.id.btn3:
case R.id.btn4:
case R.id.btn5:
case R.id.btn6:
case R.id.btn7:
case R.id.btn8:
case R.id.btn9:
toInput ((Button) v);
break;
case R.id.btn0:
input = new StringBuffer ();
input.append (btn0.getText () toString ().);
et.setText (input.toString ());
break;
case R.id.btn12:
toDelete ();
break;
default:
break;
}
/ / Determine the position of the cursor on the last side
CharSequence text = et.getText ();
Selection.setSelection ((Spannable) text, text.length ());
}


/ / Used to press a button when the situation EditText
private void toDelete ()
{
length = input.length ();
if (length> 0)
{
input = input.deleteCharAt (input.length () - 1);
et.setText (input);
}
}

/ / Used to click buttons to enter
private void toInput (Button btn)
{
input.append (btn.getText () toString ().);
et.setText (input.toString ());
}

/ / Long press del key, empty EditText
private OnLongClickListener mListener = new OnLongClickListener ()
{

@ Override
public boolean onLongClick (View v)
{
int length = input.length ();
if (length> 0)
{
input.delete (0, input.length () - 1);
et.setText (input);
}
return false;
}
};

@ 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;
}

}


I have to do is dial interface
Here is the source
activity_main.xmlandroid: id = "@ + id/TableLayout01"
xmlns: android = "http://schemas.android.com/apk/res/android"
xmlns: tools = "http://schemas.android.com/tools"
android: layout_width = "match_parent"
android: layout_height = "wrap_content"
android: layout_gravity = "bottom"
>

android: id = "@ + id/tv1"
android: layout_width = "320dip"
android: layout_height = "wrap_content"
android: layout_weight = "1.00"
android: hint = "@ string / text"
android: gravity = "right"
android: phoneNumber = "true" />

android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
>

No comments:

Post a Comment