
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.xml
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: 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_height = "wrap_content"
>
android: id = "@ + id/btn1"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn1" />
android: id = "@ + id/btn2"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn2" />
android: id = "@ + id/btn3"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn3" />
android: layout_height = "wrap_content"
>
android: id = "@ + id/btn4"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn4" />
android: id = "@ + id/btn5"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn5" />
android: id = "@ + id/btn6"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn6" />
android: layout_height = "wrap_content"
>
android: id = "@ + id/btn7"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn7" />
android: id = "@ + id/btn8"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn8" />
android: id = "@ + id/btn9"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn9" />
android: layout_height = "wrap_content"
>
android: id = "@ + id/btn11"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn11" />
android: id = "@ + id/btn0"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn0" />
android: id = "@ + id/btn12"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn12" />
Big knees and begged God to help see why, I am a novice, scholarship Andrews days. Teacher assignments
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
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;
}
}
Reply:
android: 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"
>
android: id = "@ + id/btn1"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn1" />
android: id = "@ + id/btn2"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn2" />
android: id = "@ + id/btn3"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn3" />
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
>
android: id = "@ + id/btn4"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn4" />
android: id = "@ + id/btn5"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn5" />
android: id = "@ + id/btn6"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn6" />
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
>
android: id = "@ + id/btn7"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn7" />
android: id = "@ + id/btn8"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn8" />
android: id = "@ + id/btn9"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn9" />
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
>
android: id = "@ + id/btn11"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn11" />
android: id = "@ + id/btn0"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn0" />
android: id = "@ + id/btn12"
android: layout_width = "100dip"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: onClick = "myclick"
android: text = "@ string/btn12" />
Reply:
I faint, the following statement mView where initialization Yeah? ?
btn0 = (Button) mView.findViewById (R.id.btn0);
Reply:
I was white, scholarship Andrews wrote two days ...... the teacher let the job, pointing Guiqiu
Reply:
Do you have that particular class in that particular activity?
Reply:
Hello! Is a null pointer error, not initialized object class object declaration before the assignment after you double-click Caseby use the following line will be targeted to the specific location of the error. . . . A closer look
No comments:
Post a Comment