package com.example.desktop.mirror;
import android.content.Intent;
import android.provider.Settings;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.MenuItem;
import android.view.MenuItem;
import android.widget.EditText;
import java.util.Scanner;
public class MainActivity extends ActionBarActivity {
public EditText a;
public String entereda;
public EditText b;
public String enteredb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void OnClick(View v){
a = (EditText) findViewById(R.id.first_text);
b = (EditText) findViewById(R.id.second_text);
if(boolean entereda){
Intent i = new (this, reverseactivity.class);
startActivity(i);
}
@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 menu) {
// 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 = menu.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(menu);
}
我是Java和Android的新手,所以我不能更具体。 我的问题可能是一个愚蠢的问题,因为它是一个简单的用Java实现,但是在Android上实现,我在代码上苦苦挣扎。
答案 0 :(得分:6)
尝试这个最小代码(2行,不包括Sysyem.out.println()
):
// The big works ;)
StringBuffer buffer = new StringBuffer("Test!");
buffer.reverse();
// Test it out
System.out.println(buffer); // .toString());
输出:
!tseT
必需的导入:
java.lang.StringBuffer
答案 1 :(得分:1)
public void OnClick (View v){
a = (EditText) findViewById(R.id.first_text);
b = (EditText) findViewById(R.id.second_text);
StringBuilder s = new StringBuilder(100);
String entereda = a.getText().toString();
int str_len = entereda.length();
for (int i = (str_len - 1); i >= 0; i--) {
System.out.print(entereda.charAt(i));
s.append(entereda.charAt(i));
}
答案 2 :(得分:0)
不是很熟悉android,但要扭转字符串:
public static String reverse(String toReverse) {
Stack<Character> letters = new Stack<Character>();
for(char c:toReverse.toCharArray()) {
letters.push(c);
}
StringBuilder sb = new StringBuilder();
while(!letters.empty()) {
sb.append(letters.pop());
}
return sb.toString();
}
只需使用Thread显示结果并将结果设置为您想要的值。
Java与Android没有区别,只是Android具有内置的GUI功能。
你如何让代码显示在java中?