demo
package com.app.cceasy.macconvert; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.EditText; import android.widget.TextView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void getResult(View view){ EditText edit_text1 = (EditText) findViewById(R.id.edit_text1); EditText edit_text2 = (EditText) findViewById(R.id.edit_text2); EditText edit_text3 = (EditText) findViewById(R.id.edit_text3); TextView result = (TextView) findViewById(R.id.textview); Long macStart = Long.parseLong(edit_text1.getText().toString(),16); Long num1 = Long.parseLong(edit_text2.getText().toString(),10); Long num2 = Long.parseLong(edit_text3.getText().toString(),10); result.setTextSize(30); result.setText(macStart.toHexString(macStart+num1*num2-1)); //result.setText(edit_text1.getText().toString()+edit_text2.getText().toString()+edit_text3.getText().toString()); } public void clearData(View view){ EditText edit_text1 = (EditText) findViewById(R.id.edit_text1); EditText edit_text2 = (EditText) findViewById(R.id.edit_text2); EditText edit_text3 = (EditText) findViewById(R.id.edit_text3); TextView result = (TextView) findViewById(R.id.textview); edit_text1.setText(""); edit_text2.setText(""); edit_text3.setText(""); result.setText(""); //(EditText) findViewById(R.id.edit_text2).setText(""); //(EditText) findViewById(R.id.edit_text3).setText(""); // (TextView) findViewById(R.id.textview).setText(""); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/edit_text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:hint="macstart" /> <EditText android:id="@+id/edit_text2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="num1" /> <EditText android:id="@+id/edit_text3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="num2" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="计算" android:onClick="getResult" /> </LinearLayout > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:hint="result" /> </LinearLayout > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="bottom|right"> <Button android:id="@+id/cleardata" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="clearData" android:hint="清除" /> </LinearLayout > </LinearLayout >