Hi all, ive just started lookin up to Java and creating app, i know i should start and improove slowly, but i need quickly some helps with makin a Translator.apk using Bing API translator, cause google one are now only aviable if u pay them.
i saw a litle exemple where i downloaded the Jar file(which i put it in /libs and mine came out like this:
import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity implements OnClickListener {
EditText in, out;
Button trns;
String inPut;
@Override
protected void onCreate() {
// TODO Auto-generated method stub
Translate.setClientId("hidden");
Translate.setClientSecret("hidden");
super.onCreate();
setContentView(R.layout.activity_main);
trns = (Button) findViewById(R.id.button1);
in = (EditText) findViewById(R.id.editText1);
out = (EditText) findViewById(R.id.editText2);
inPut = in.getText().toString();
trns.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
String translatedText = Translate.execute(inPut, Language.GERMAN,
Language.FRENCH);
out.setText(translatedText);
} catch (Exception e) {
e.printStackTrace();
}
}
}
problaby its all wrong i know, thats why i need help
Guess i have to add Internet permission to the manifest(how ? and do i have to make some controll after?)
I studied at school some basic C# so im used to the grouBox which i didnt find with eclipse. What's the nearest thing with it where i can put a list of all selectable language to translate?
Hope somebody could help me, ty
Related
Hi All! I'm trying to create an always-op-top button/clickable-image which stays on top of all the windows all the time. The proof of concept is here http://www.appbrain.com/app/smart-taskbar-(sidebar)/com.smart.taskbar and here http://forum.xda-developers.com/showthread.php?t=865525 I'm following this example code http://android.git.kernel.org/?p=pl...6429aaa5ccf6ecf311dfb3af0f3ccbf5f8d29;hb=HEAD
I have been successful and have a running service now. The service displays some text on top left corner of screen all the time while user can freely interact with rest of apps in normal manner. What I'm doing is subclass ViewGroup and add it to root window manager with flag TYPE_SYSTEM_OVERLAY. Now I want to add a button/clickable-image in place of this text which can receive touch events on itself. I tried overriding "onTouchEvent" for the whole ViewGroup but it does not receive any event. How can I receive events only on certain parts of my always-on-top view group? Kindly suggest.
Code:
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class HUD extends Service {
HUDView mView;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
Toast.makeText(getBaseContext(),"onCreate", Toast.LENGTH_LONG).show();
mView = new HUDView(this);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
0,
// WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
// | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.RIGHT | Gravity.TOP;
params.setTitle("Load Average");
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(mView, params);
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(getBaseContext(),"onDestroy", Toast.LENGTH_LONG).show();
if(mView != null)
{
((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(mView);
mView = null;
}
}
}
class HUDView extends ViewGroup {
private Paint mLoadPaint;
public HUDView(Context context) {
super(context);
Toast.makeText(getContext(),"HUDView", Toast.LENGTH_LONG).show();
mLoadPaint = new Paint();
mLoadPaint.setAntiAlias(true);
mLoadPaint.setTextSize(10);
mLoadPaint.setARGB(255, 255, 0, 0);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawText("Hello World", 5, 15, mLoadPaint);
}
@Override
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) {
}
@Override
public boolean onTouchEvent(MotionEvent event) {
//return super.onTouchEvent(event);
Toast.makeText(getContext(),"onTouchEvent", Toast.LENGTH_LONG).show();
return true;
}
}
Hello.
I am fighting with this,unfortunately it FC's for me,while using same code.
Can you please help me to solve the problem?
TomasNM said:
Hello.
I am fighting with this,unfortunately it FC's for me,while using same code.
Can you please help me to solve the problem?
Click to expand...
Click to collapse
Nevermind man.
After 3 weeks of waiting for some help,I did it myself.
Thank you...
TomasNM said:
Nevermind man.
After 3 weeks of waiting for some help,I did it myself.
Thank you...
Click to expand...
Click to collapse
How did you solve that problem???
I modified this:
http://www.pocketmagic.net/android-overlay-cursor/
Unfortunately,I didn't made it clickable(movable around the screen),so all dimensions and positions are hardcoded.
I can modify it for myself anytime and noone use my app.
Hello XDA,
So I've not found anyone properly discussing this. If they do, please link me to the page and don't flame
I've been making an app for my school and so far, I've been doing alright. But now I have run into a problem which seems to be very hard to solve for me alone.
Namely, I have an EditText and a Button in one Activity and a WebView as a different Activity.
I'm trying to get the EditText String into the WebView URL (String being variable, Button initiating the WebView), but get a lot of errors, some not even related to that.
I would really appreciate it if someone could have a look at the code and help me with this
MyWebView.java:
Code:
package bas.sie.Antonius;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MyWebView extends Activity {
WebView mWebView;
EditText mEtxtStudentNum;
static String StudentNumFromHome = bas.sie.Antonius.Home.StudentNum;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl("http://carmelcollegegouda.nl/site_ant/roosters/standaardroosters/Lee1_" + StudentNumFromHome + ".htm");
}
}
Home.java (Homescreen):
Code:
package bas.sie.Antonius;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Home extends Activity {
Button mBtnStSchedule;
static EditText mEtxtStudentNum;
static final String StudentNum = mEtxtStudentNum.getText().toString();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button next = (Button) findViewById(R.id.BtnStSchedule);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), MyWebView.class);
startActivityForResult(myIntent, 0);
}
});
// TODO Auto-generated method stub
}
}
AntoniusActivity.java (Main):
Code:
package bas.sie.Antonius;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TabHost;
public class AntoniusActivity extends TabActivity {
WebView mWebView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, Home.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("home").setIndicator("Home",
res.getDrawable(R.drawable.ic_tab_home))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, External.class);
spec = tabHost.newTabSpec("external").setIndicator("External",
res.getDrawable(R.drawable.ic_tab_external))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Contact.class);
spec = tabHost.newTabSpec("contact").setIndicator("Contact",
res.getDrawable(R.drawable.ic_tab_contact))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
In AntoniusActivity, the private class HelloWebViewClient is underlined with yellow (never used), specifically the bit "HelloWebViewClient".
It's also throwing FC's at startup, and errors in LogCat, but I'll post those later on, as it's 10.30 PM here, and school goes on
Thanks in advance,
bassie1995
No suggestions yet?
How you doin'? Greetings from my GT-I9000!
Ok so today i started my first Android Application in eclipse. I am VERY new at coding so bear with me. So i looked online on how to open a new screen when i press a button, but my question is, how do i open a different screen when i press a different button on the same page? Because you cant just copy and paste the same code for the first button because it gives you duplicate errors. Can anyone tell me what i can copy/paste or do to get my second button to go to a different screen? Thanks!
main.class (or java)
Code:
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class MinecraftInfoProActivity extends Activity {
Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addListenerOnButton();
}
public void addListenerOnButton(){
final Context context = this;
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent intent = new Intent(context, Mobs.class);
startActivity(intent);
}
});
}
}
main.xml
Code:
animals.class (or java) (this is my second page i wanna hook my second button up to)
Code:
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Animals extends Activity {
}
animals.xml
Code:
AndroidManifest.xml
Code:
I am trying to hook button2 in main.xml so that when clicked, it takes me to the animals.xml page. Any help is appreciated guys. Thanks
EDIT: Sorry about the smily faces in the code..im not sure what that is about.
Mod Edit: Moved to Q&A
Scoutamis said:
Ok so today i started my first Android Application in eclipse. I am VERY new at coding so bear with me. So i looked online on how to open a new screen when i press a button, but my question is, how do i open a different screen when i press a different button on the same page? Because you cant just copy and paste the same code for the first button because it gives you duplicate errors. Can anyone tell me what i can copy/paste or do to get my second button to go to a different screen? Thanks!
main.class (or java)
Code:
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class MinecraftInfoProActivity extends Activity {
Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addListenerOnButton();
}
public void addListenerOnButton(){
final Context context = this;
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent intent = new Intent(context, Mobs.class);
startActivity(intent);
}
});
}
}
main.xml
Code:
animals.class (or java) (this is my second page i wanna hook my second button up to)
Code:
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Animals extends Activity {
}
animals.xml
Code:
AndroidManifest.xml
Code:
I am trying to hook button2 in main.xml so that when clicked, it takes me to the animals.xml page. Any help is appreciated guys. Thanks
EDIT: Sorry about the smily faces in the code..im not sure what that is about.
Click to expand...
Click to collapse
Use CODE] /CODE] If you dont want smileys.
Sent from my GT-I5800 using XDA App
rubensollie said:
Use CODE] /CODE] If you dont want smileys.
Sent from my GT-I5800 using XDA App
Click to expand...
Click to collapse
I did so idk why it isn't working...anyway does ANYONE have any help?
Sent from my SAMSUNG-SGH-I727 using xda premium
Hope this helps ya out
In the main.xml, you can specify an event handler method for button2 by adding this in button2's xml declarations
Code:
android:onClick="yourMethodName"
That is a quick replacement for
Code:
button.setOnClickListener(new OnClickListener(){
public void yourMethodName(View view) {
Intent intent = new Intent(context, Mobs.class);
startActivity(intent);
}
});
Of course replace 'yourMethodName' with the method that you want to handle the click action. You can use this for button1 as well, just specify the onClick property in main.xml under button1. You need to create a method in your MinecraftInfoProActivity class that will be the handler for the button, so say you create a method called 'Button2Handler". To open up Animals (which you have to write the code to display the animals.xml) you could use this method.
Code:
public void Button2Handler(View view) {
Intent intent = new Intent(context, Animals.class);
startActivity(intent);
}
Hope this gives you what you need, as it's just a quick basic intro into it
regaw_leinad said:
Hope this helps ya out
In the main.xml, you can specify an event handler method for button2 by adding this in button2's xml declarations
Code:
android:onClick="yourMethodName"
That is a quick replacement for
Code:
button.setOnClickListener(new OnClickListener(){
public void yourMethodName(View view) {
Intent intent = new Intent(context, Mobs.class);
startActivity(intent);
}
});
Of course replace 'yourMethodName' with the method that you want to handle the click action. You can use this for button1 as well, just specify the onClick property in main.xml under button1. You need to create a method in your MinecraftInfoProActivity class that will be the handler for the button, so say you create a method called 'Button2Handler". To open up Animals (which you have to write the code to display the animals.xml) you could use this method.
Code:
public void Button2Handler(View view) {
Intent intent = new Intent(context, Animals.class);
startActivity(intent);
}
Hope this gives you what you need, as it's just a quick basic intro into it
Click to expand...
Click to collapse
Omg thank you that helped soooo much
Sent from my SAMSUNG-SGH-I727 using xda premium
Hi i'm trying to make an app with a button that free cache of the phone.. This is the code:
Code:
package com.mkyong.android;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import java.io.IOException;
import com.example.toast.R;
public class MainActivity extends Activity {
private Button button;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab1);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@SuppressLint("SdCardPath")
@Override
public void onClick(View arg0) {
final Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("su -c 'echo 3 > /proc/sys/vm/drop_caches'");
Toast.makeText(MainActivity.this, "Script lanciato con `successo, memoria svuotata.", Toast.LENGTH_LONG).show();`
}
catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
Well i've got no errors but nothing happen.. When i press the button the free ram memory rest the same. (to see the free memory i open the terminal emulator and i write the "free" command"). Someone can help me? What's wrong?
Hi, I having some problem with this simple code. I don't undestrand because ADT impost fields as EditText, TextView and Button as field final. I think that there' some errore in my code, I admit that is one of my first times that i programming for andoird, so have patience with me.
I apologize if I wrong section :silly:
That's my code:
package com.example.buttoncerca;
import android.os.Bundle;
import android.app.Activity;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class RisponditoreInterattivoActivity extends Activity implements Lista {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_risponditore_interattivo);
final EditText text = (EditText)this.findViewById(R.id.campoNome);
Button button = (Button)this.findViewById(R.id.buttone);
final TextView tv = (TextView)this.findViewById(R.id.testoSaluto);
button.setOnClickListener(new OnClickListener(){
public void onClick(View arg0){
Editable nome = text.getText();
String s = nome.toString();
for(int c =0; c<3; c++){
if(toppings[c].equals(s)){
tv.setText(toppings[c] + " si butta nel " + cestino[c]);
} //End if
}//End for
}//End onClick
});
}
}
Click to expand...
Click to collapse
I implements inteface Lista, this is code:
package com.example.buttoncerca;
public interface Lista {
String[] toppings = {"Plastica", "Legno", "Cartone"};
String[] cestino = {"Cestino plastica", "Cestino legno", "Cestino cartone"};
}
Click to expand...
Click to collapse
And... what's the problem? Please post it "as is".
You need to instantiate the editable first, with BUFFERTYPE.EDITABLE, because in your current case you are casting a charseq to an editable so that's likely the exception you are getting (hard to know without a logcat). See here:
http://developer.android.com/reference/android/widget/EditText.html#getText()
Sent from my Amaze 4G using xda app-developers app