0
我在仿真器上測試我的應用程序並且工作正常。當我在真實設備上啓動它時,它不起作用(組件正常加載)。它只包含一個文本區域,只要按下「1」,就應該在上面寫上「Hello,world」。我使用:我的應用程序只能在仿真器上運行,而不能在真實設備上運行
import android.media.MediaPlayer;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends ActionBarActivity {
String current_string;
int length;
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et = (EditText) findViewById(R.id.editText);
et.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_1)) {
et.setText("Hello, world!");
current_string = et.getText().toString();
length = current_string.length();
et.setSelection(length);
return true;
}
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;
}
@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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
和XML我使用:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.testingname.testapp.app.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
感謝您的回答。如果我訂購併使用迷你藍牙鍵盤,您是否認爲它會以我發佈的方式工作? http://www.horace.org/blog/wp-content/uploads/2012/07/Mini-Palm-Sized-iPad-Bluetooth-Keyboard_2.jpg –
我其實不確定,我從來沒有用過。 –
好的謝謝你的幫助,我想用textwatcher,看看它是否工作 –