help! diference with numbers.... - Java for Android App Development

okay I need help....
I'm a beginner to Android and Java (both of them and I am learning....)
So I thought of making a simple app but its got an annoying problem...
Its a calculator so it has some number keys ...the problem is that different keys give out different numbers like 2 prints out 9
MainActivity
Code:
package com.aN.calculator1;
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.TextView;
public class MainActivity extends Activity implements OnClickListener {
Button mb1, mb2, mb3, mb4, mb5, mb6, mb7, mb8, mb9, mb10, mb11, mb12, mb13, mb14, mb15, mb16 ;
TextView mTextView1 ;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView1 = (TextView)findViewById(R.id.textView1);
mb1 = (Button)findViewById(R.id.b1);
mb2 = (Button)findViewById(R.id.b2);
mb3 = (Button)findViewById(R.id.b3);
mb4 = (Button)findViewById(R.id.b4);
mb5 = (Button)findViewById(R.id.b5);
mb6 = (Button)findViewById(R.id.b6);
mb7 = (Button)findViewById(R.id.b7);
mb8 = (Button)findViewById(R.id.b8);
mb9 = (Button)findViewById(R.id.b9);
mb10 = (Button)findViewById(R.id.b10);
mb11 = (Button)findViewById(R.id.b11);
mb12 = (Button)findViewById(R.id.b12);
mb13 = (Button)findViewById(R.id.b13);
mb14 = (Button)findViewById(R.id.b14);
mb15 = (Button)findViewById(R.id.b15);
mb16 =(Button)findViewById(R.id.b16);
mb1.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
mTextView1.setText("");
}
});
mb2.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
if(mTextView1 != null || !mTextView1.getText().equals(""))
{
mTextView1.append("1");
}else {
mTextView1.setText("1");
}
}
});
mb3.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
if(mTextView1 !=null || !mTextView1.getText().equals(""))
{
mTextView1.append("2");
}
else {
mTextView1.setText("2");
}
}
});
mb4.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
if(mTextView1 !=null || !mTextView1.getText().equals(""))
{
mTextView1.append("3");
}
else {
mTextView1.setText("3");
}
}
});
mb5.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
if(mTextView1 !=null || !mTextView1.getText().equals(""))
{
mTextView1.append( "4");
}
else {
mTextView1.setText("4");
}
}
});
mb6.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
if(mTextView1 !=null || !mTextView1.getText().equals(""))
{
mTextView1.append("5");
}
else {
mTextView1.setText("5");
}
}
});
mb7.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
if(mTextView1 !=null || !mTextView1.getText().equals(""))
{
mTextView1.append("6");
}
else {
mTextView1.setText("6");
}
}
});
mb8.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
if(mTextView1 !=null || !mTextView1.getText().equals(""))
{
mTextView1.append("7");
}
else {
mTextView1.setText("7");
}
}
});
mb9.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
if(mTextView1 !=null || !mTextView1.getText().equals(""))
{
mTextView1.append("8");
}
else {
mTextView1.setText("8");
}
}
});
mb10.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
if(mTextView1 !=null || !mTextView1.getText().equals(""))
{
mTextView1.append("9");
}
else {
mTextView1.setText("9");
}
}
});
mb12.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
if(mTextView1 !=null || !mTextView1.getText().equals(""))
{
mTextView1.append("0");
}
else {
mTextView1.setText("0");
}
}
});
}
[user=439709]@override[/user]
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;
}
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
Activitymain.xml
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rootRL"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="20dip"
android:layout_above="@+id/b1"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<Button
android:id="@+id/b14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/b11"
android:text="/" />
<Button
android:id="@+id/b11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/b14"
android:layout_alignParentLeft="true"
android:text="+" />
<Button
android:id="@+id/b16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/b13"
android:layout_alignParentRight="true"
android:layout_below="@+id/b11"
android:text="=" />
<Button
android:id="@+id/b13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/b11"
android:layout_alignBottom="@+id/b11"
android:layout_alignParentRight="true"
android:text="-" />
<Button
android:id="@+id/b12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/b14"
android:layout_alignLeft="@+id/b15"
android:layout_alignRight="@+id/b15"
android:text="0" />
<Button
android:id="@+id/b4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/b6"
android:layout_alignLeft="@+id/b7"
android:layout_alignParentRight="true"
android:text="3" />
<Button
android:id="@+id/b7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/b9"
android:layout_alignLeft="@+id/b13"
android:layout_alignParentRight="true"
android:text="6" />
<Button
android:id="@+id/b8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/b12"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/b11"
android:text="7" />
<Button
android:id="@+id/b10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/b12"
android:layout_alignLeft="@+id/b13"
android:layout_alignParentRight="true"
android:text="9" />
<Button
android:id="@+id/b5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/b8"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/b8"
android:text="4" />
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/b3"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="Clear" />
<Button
android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/b5"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/b5"
android:text="1" />
<Button
android:id="@+id/b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/b6"
android:layout_centerHorizontal="true"
android:text="2" />
<Button
android:id="@+id/b15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/b9"
android:layout_alignParentBottom="true"
android:text="X" />
<Button
android:id="@+id/b9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/b3"
android:layout_alignRight="@+id/b3"
android:layout_below="@+id/b6"
android:text="8" />
<Button
android:id="@+id/b6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/b8"
android:layout_alignLeft="@+id/b3"
android:layout_alignRight="@+id/b3"
android:text="5" />
</RelativeLayout>
Thanks in Advance waiting for your help

I can't help you now as I'm on my way out.
But just a tip, try naming you buttons in such a way that you can recognize it easily.
For example, your Button b1 is Clear, b2 is "1", b3 is "2" so on and so forth, which is so confusing.
Try naming is as :bClear, bOne, bTwo, bExit, bMinus, bPlus and such.
If no one helps you out the moment I reach home, I'll be sure to help you out.
:highfive:
EDIT :
Also, you can remove
Code:
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
}
and
Code:
.. implement OnClickListener {
since you've set a OnClickListener on each button individually.

See my thread!
Edit:
Oops I am an "idiot" you already voted there!

[==)BULLET(==] said:
See my thread!
Edit:
Oops I am an "idiot" you already voted there!
Click to expand...
Click to collapse
sorry what ??
i didn't get you...
Sent from my GT-S5360 using xda app-developers app

anubhavrev said:
sorry what ??
i didn't get you...
Sent from my GT-S5360 using xda app-developers app
Click to expand...
Click to collapse
You voted the poll on his thread that he's an idiot. :/
Anyway, I see no wrong with your code. The numbers are shown/typed according to what is pressed. Mind explaining the error a little more?

frenzyboi said:
You voted the poll on his thread that he's an idiot. :/
Anyway, I see no wrong with your code. The numbers are shown/typed according to what is pressed. Mind explaining the error a little more?
Click to expand...
Click to collapse
yea i jst realized bout voting idiot on his poll ....
@bullet
m sorry man ... chck pm ....
@frenzyboi
the problem is lyk i press 2 the textview shows 9 and most of d buttons are messed up similarly
.....
Edit:
P.S.- i have heard dat i'll hav to pay 25$ for uploading apps to gplay .... is it so ¿?
Sent from my GT-S5360 using xda app-developers app

Yes you need to pay $25 for uploading apps to gplay (even for free ones )!

[==)BULLET(==] said:
Yes you need to pay $25 for uploading apps to gplay (even for free ones )!
Click to expand...
Click to collapse
u read pm?
Sent from my GT-S5360 using xda app-developers app

anubhavrev said:
u read pm?
Sent from my GT-S5360 using xda app-developers app
Click to expand...
Click to collapse
you read yours!!

[==)BULLET(==] said:
you read yours!!
Click to expand...
Click to collapse
xda app doesn't hav notifications....
first thing to do aftr learning java - fix this app
Sent from my GT-S5360 using xda app-developers app

I'm having no error. Press 2 = 2, press 5 = 5.
Someone else please test the APK below and see if it happens to you too.

frenzyboi said:
I'm having no error. Press 2 = 2, press 5 = 5.
Someone else please test the APK below and see if it happens to you too.
Click to expand...
Click to collapse
Confirmed working.
Well done
Would try to include these buttons in my calculator!

frenzyboi said:
I'm having no error. Press 2 = 2, press 5 = 5.
Someone else please test the APK below and see if it happens to you too.
Click to expand...
Click to collapse
thanx man but could u tell how you fixed it ¿?
Sent from my GT-S5360 using xda app-developers app

anubhavrev said:
thanx man but could u tell how you fixed it ¿?
Sent from my GT-S5360 using xda app-developers app
Click to expand...
Click to collapse
I did not fix it! I'm using your code, with totally no error. LOL

Could you tell me which device u use?
Right now i will try it on another virtual device since my first virtual device and phone both have gingerbread
Mayb also try fixes from first reply...
Thanx a lot man for helping me....

anubhavrev said:
Could you tell me which device u use?
Right now i will try it on another virtual device since my first virtual device and phone both have gingerbread
Mayb also try fixes from first reply...
Thanx a lot man for helping me....
Click to expand...
Click to collapse
I'm using Xperia Ray on Android 4.2.2 P.A.C rom.
Android version shouldn't be a problem in this. The code is written correct [as far as I can see] and each button is registered to a correct number to display.

okay I finally found the fault....
i just removed the line declaring background png from the mainactivity.xml
and it worked
now could you tell me how to properly set a background ?
EDIT:is it fine if i set a Onclicklistener on each button individually ? or if there is a better way what wud it be ?

you sure it is the right way becoz removing that particular line stopped the errors...

@Ichigo yes
sorry i should have quoted ....

Ichigo said:
Did you actually put @drawable/bg? Replace bg with your background image.
Click to expand...
Click to collapse
its working ..i had earlier renamed the background to bg
this tym made some minor changes in the xml instead of being lazy
Sent from my GT-S5360 using xda app-developers app

Related

[Q] Can anybody help me!!??

Hello XDA users! I'm trying to develop an Android Launcher. First I want to "call" all apps in a Grid View. All works great, but appears a List View and I want a Grid. This is my code, where is the problem?
MainActivity.java
Code:
public class MainActivity extends Activity {
private GridView mGrid;
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set layout for the main screen
setContentView(R.layout.layout_main);
// load list application
mGrid = (GridView)findViewById(R.id.lvApps);
// create new adapter
AppInfoAdapter adapter = new AppInfoAdapter(this, Utilities.getInstalledApplication(this), getPackageManager());
// set adapter to list view
mGrid.setAdapter(adapter);
// implement event when an item on list view is selected
mGrid.setOnItemClickListener(new OnItemClickListener() {
[user=439709]@override[/user]
public void onItemClick(AdapterView parent, View view, int pos, long id) {
// get the list adapter
AppInfoAdapter appInfoAdapter = (AppInfoAdapter)parent.getAdapter();
// get selected item on the list
ApplicationInfo appInfo = (ApplicationInfo)appInfoAdapter.getItem(pos);
// launch the selected application
Utilities.launchApp(parent.getContext(), getPackageManager(), appInfo.packageName);
}
});
}
}
AppInfo.java
Code:
public class AppInfoAdapter extends BaseAdapter {
private Context mContext;
private List mListAppInfo;
private PackageManager mPackManager;
public AppInfoAdapter(Context c, List list, PackageManager pm) {
mContext = c;
mListAppInfo = list;
mPackManager = pm;
}
[user=439709]@override[/user]
public int getCount() {
return mListAppInfo.size();
}
[user=439709]@override[/user]
public Object getItem(int position) {
return mListAppInfo.get(position);
}
[user=439709]@override[/user]
public long getItemId(int position) {
return position;
}
[user=439709]@override[/user]
public View getView(int position, View convertView, ViewGroup parent) {
// get the selected entry
ApplicationInfo entry = (ApplicationInfo) mListAppInfo.get(position);
// reference to convertView
View v = convertView;
// inflate new layout if null
if(v == null) {
LayoutInflater inflater = LayoutInflater.from(mContext);
v = inflater.inflate(R.layout.layout_appinfo, null);
}
// load controls from layout resources
ImageView ivAppIcon = (ImageView)v.findViewById(R.id.ivIcon);
TextView tvAppName = (TextView)v.findViewById(R.id.tvName);
// set data to display
ivAppIcon.setImageDrawable(entry.loadIcon(mPackManager));
tvAppName.setText(entry.loadLabel(mPackManager));
// return view
return v;
}
}
Utilities.java
Code:
public class Utilities {
/*
* Get all installed application on mobile and return a list
* [user=955119]@param[/user]cContext of application
* [user=2056652]@return[/user]list of installed applications
*/
public static List<ApplicationInfo> getAllInstalledApplications(Context context) {
List<ApplicationInfo> installedApps = context.getPackageManager().getInstalledApplications(PackageManager.PERMISSION_GRANTED);
List<ApplicationInfo> launchableInstalledApps = new ArrayList<ApplicationInfo>();
for(int i =0; i<installedApps.size(); i++){
if(context.getPackageManager().getLaunchIntentForPackage(installedApps.get(i).packageName) != null){
//If you're here, then this is a launch-able app
launchableInstalledApps.add(installedApps.get(i));
}
}
return launchableInstalledApps;
}
/*
* Launch an application
* [user=955119]@param[/user]cContext of application
* [user=955119]@param[/user]pmthe related package manager of the context
* [user=955119]@param[/user]pkgNameName of the package to run
*/
public static boolean launchApp(Context c, PackageManager pm, String pkgName) {
// query the intent for lauching
Intent intent = pm.getLaunchIntentForPackage(pkgName);
// if intent is available
if(intent != null) {
try {
// launch application
c.startActivity(intent);
// if succeed
return true;
// if fail
} catch(ActivityNotFoundException ex) {
// quick message notification
Toast toast = Toast.makeText(c, "Application Not Found", Toast.LENGTH_LONG);
// display message
toast.show();
}
}
// by default, fail to launch
return false;
}
}
Sorry if I put so much code but I don't know where is the problem.
Enviado desde mi GT-S5570I usando Tapatalk 2
You didn't post the layout files.
Dark3n said:
You didn't post the layout files.
Click to expand...
Click to collapse
Thank's for the info! I edited this now
Enviado desde mi GT-S5570I usando Tapatalk 2
Please! Help!
Enviado desde mi GT-S5570I usando Tapatalk 2
DannyGM16 said:
Please! Help!
Enviado desde mi GT-S5570I usando Tapatalk 2
Click to expand...
Click to collapse
By layout files he ment .xml
File
Sent from my GT-S5302 using Tapatalk 2
sak-venom1997 said:
By layout files he ment .xml
File
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
Dark3n said:
You didn't post the layout files.
Click to expand...
Click to collapse
Enviado desde mi GT-S5570I usando Tapatalk 2
I'm confused!
I fixed this error with android:numColumns="4" But I have other two errors, the first is that the name of the app is in the right and I want it down, and the other error is that the App images are not ajusted at her size.
Sorry for my english errors (a lot of errors), today I'm really stupid!! But... do you understad what I mean?
DannyGM16 said:
Enviado desde mi GT-S5570I usando Tapatalk 2
I'm confused!
I fixed this error with android:numColumns="4" But I have other two errors, the first is that the name of the app is in the right and I want it down, and the other error is that the App images are not ajusted at her size.
Sorry for my english errors (a lot of errors), today I'm really stupid!! But... do you understad what I mean?
Click to expand...
Click to collapse
I am sorry, but we cannot help you without this file:
Code:
/res/layout/layout_appinfo.xml
layout_appinfo.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="(xmlns deleted)"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="5dip"
>
<ImageView
android:id="@+id/ivIcon"
android:layout_width="42px"
android:layout_height="42px"
android:layout_marginRight="5dip"
android:scaleType="center"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
>
<TextView
android:id="@+id/tvName"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center_vertical"
/>
</LinearLayout>
</LinearLayout>
layout_main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="(xmlns deleted)"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/ExampleButton"
android:text="Example Button"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<GridView
android:id="@+id/all_apps"
android:background="@android:color/black"
android:persistentDrawingCache="animation|scrolling"
android:alwaysDrawnWithCache="true"
android:scrollbars="none"
android:drawSelectorOnTop="false"
android:numColumns="4"
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
</LinearLayout>
Thank's for your help, I'm very hope to find you! And Now I fix the java archives, now you can try my project in an emulator.
Enviado desde mi GT-S5570I usando Tapatalk 2
DannyGM16 said:
layout_appinfo.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="(xmlns deleted)"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="5dip"
>
<ImageView
android:id="@+id/ivIcon"
android:layout_width="42px"
android:layout_height="42px"
android:layout_marginRight="5dip"
android:scaleType="center"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
>
<TextView
android:id="@+id/tvName"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center_vertical"
/>
</LinearLayout>
</LinearLayout>
layout_main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="(xmlns deleted)"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/ExampleButton"
android:text="Example Button"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<GridView
android:id="@+id/all_apps"
android:background="@android:color/black"
android:persistentDrawingCache="animation|scrolling"
android:alwaysDrawnWithCache="true"
android:scrollbars="none"
android:drawSelectorOnTop="false"
android:numColumns="4"
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
</LinearLayout>
Thank's for your help, I'm very hope to find you! And Now I fix the java archives, now you can try my project in an emulator.
Enviado desde mi GT-S5570I usando Tapatalk 2
Click to expand...
Click to collapse
Do this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="(xmlns deleted)"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip"
>
<ImageView
android:id="@+id/ivIcon"
android:layout_width="42px"
android:layout_height="42px"
android:layout_marginRight="5dip"
android:scaleType="center"
android:alignParentTop="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="@+id/tvName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/ivIcon"
/>
</RelativeLayout>
(I hope that it works. I did not test it.)
nikwen said:
Do this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="(xmlns deleted)"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip"
>
<ImageView
android:id="@+id/ivIcon"
android:layout_width="42px"
android:layout_height="42px"
android:layout_marginRight="5dip"
android:scaleType="center"
android:alignParentTop="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="@+id/tvName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/ivIcon"
/>
</RelativeLayout>
(I hope that it works. I did not test it.)
Click to expand...
Click to collapse
You can watch the screenshoot:
1: Thank's for your help, the text is where I want.
2: New problem, the application images are too large, I knoelw that this problem is fixeable writing text in one of the java archives.
3: The text is ajusted, but not at all, watch it.
4: Thank's other time for your time and your help!
Enviado desde mi GT-S5570I usando Tapatalk 2
DannyGM16 said:
You can watch the screenshoot:
1: Thank's for your help, the text is where I want.
2: New problem, the application images are too large, I knoelw that this problem is fixeable writing text in one of the java archives.
3: The text is ajusted, but not at all, watch it.
4: Thank's other time for your time and your help!
Enviado desde mi GT-S5570I usando Tapatalk 2
Click to expand...
Click to collapse
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="(xmlns deleted)"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip"
>
<ImageView
android:id="@+id/ivIcon"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_marginRight="5dip"
android:scaleType="center"
android:alignParentTop="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="@+id/tvName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/ivIcon"
android:gravity="center"
android:maxLines="1"
/>
</RelativeLayout>
Always set size values in dp. (You might need to change the numbers though.)
That is better for supporting different screen sizes.
Welcome.
nikwen said:
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="(xmlns deleted)"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip"
>
<ImageView
android:id="@+id/ivIcon"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_marginRight="5dip"
android:scaleType="center"
android:alignParentTop="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="@+id/tvName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/ivIcon"
android:gravity="center"
android:maxLines="1"
/>
</RelativeLayout>
Always set size values in dp. (You might need to change the numbers though.)
That is better for supporting different screen sizes.
Welcome.
Click to expand...
Click to collapse
Oh! I didn't know it.
But the problem persist, the application icon must be resized.
Enviado desde mi GT-S5570I usando Tapatalk 2
DannyGM16 said:
Oh! I didn't know it.
But the problem persist, the application icon must be resized.
Enviado desde mi GT-S5570I usando Tapatalk 2
Click to expand...
Click to collapse
Yeah, do that.
You can use another scaleType for the ImageView. Use Google ("imageview scaletype"). Choose the right one.
nikwen said:
Yeah, do that.
You can use another scaleType for the ImageView. Use Google ("imageview scaletype"). Choose the right one.
Click to expand...
Click to collapse
... I don't understand you, please, show me an example
Enviado desde mi GT-S5570I usando Tapatalk 2
DannyGM16 said:
... I don't understand you, please, show me an example
Enviado desde mi GT-S5570I usando Tapatalk 2
Click to expand...
Click to collapse
For the ImageView change this
Code:
android:scaleType="center"
to
Code:
android:scaleType="centerInside"
Then change the layout_height and layout_width to the size you want.
nikwen said:
For the ImageView change this
Code:
android:scaleType="center"
to
Code:
android:scaleType="centerInside"
Then change the layout_height and layout_width to the size you want.
Click to expand...
Click to collapse
THANKS THANKS AND THANKS!! YOU ARE THE ****ING BOSS!!! YOU ARE MY GOD!! without your help I don't do it never!
Enviado desde mi GT-S5570I usando Tapatalk 2
DannyGM16 said:
THANKS THANKS AND THANKS!! YOU ARE THE ****ING BOSS!!! YOU ARE MY GOD!! without your help I don't do it never!
Enviado desde mi GT-S5570I usando Tapatalk 2
Click to expand...
Click to collapse
Welcome.
nikwen said:
Welcome.
Click to expand...
Click to collapse
And One Think, it's easy. I put a TabHost but I don't know how to put it higher?
Enviado desde mi GT-S5570I usando Tapatalk 2
DannyGM16 said:
And One Think, it's easy. I put a TabHost but I don't know how to put the text higher? Which android:xxxxxx I need to put in the text?
Enviado desde mi GT-S5570I usando Tapatalk 2
Click to expand...
Click to collapse
Enviado desde mi GT-S5570I usando Tapatalk 2
DannyGM16 said:
And One Think, it's easy. I put a TabHost but I don't know how to put it higher?
Enviado desde mi GT-S5570I usando Tapatalk 2
Click to expand...
Click to collapse
What do you mean with higher?

[Q] NoClassDefFoundError: R$layout after installing SDK and ADT updates

I update SDK to 22.0.1 and did related ADT updates. After updates my successfully running code has broken down with following error in finding xml resource-
unable to resolve static field 1108 (layout_name) in pkgname/R$layout
.
.
.
some error log....
.
.
.
java.lang.NoClassDefFoundError: pkgname.R$layout
Please tell me what can be the reason of this error and how can I resolve it?
Code:
class ProblemFixer extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
tryToFixTheProblem();
}
protected void tryToFixTheProblem()
{
try
{
cleanProject();
}
catch(FailedToFixProblemException e)
{
boolean isProblemFixed = new RestartExclipse().execute().getResponse();
if(isProblemFixed)
{
enjoy();
}
else
{
deleteAndReimportProject();
}
}
}
private void deleteAndReimportProject()
{
if(success)
{
enjoy();
}
else
{
finish();
//TODO: Open browser and search for solution;
}
}
}
Sent from my U8120 using Tapatalk 2
pedja1 said:
Code:
class ProblemFixer extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
tryToFixTheProblem();
}
protected void tryToFixTheProblem()
{
try
{
cleanProject();
}
catch(FailedToFixProblemException e)
{
boolean isProblemFixed = new RestartExclipse().execute().getResponse();
if(isProblemFixed)
{
enjoy();
}
else
{
deleteAndReimportProject();
}
}
}
private void deleteAndReimportProject()
{
if(success)
{
enjoy();
}
else
{
finish();
//TODO: Open browser and search for solution;
}
}
}
Sent from my U8120 using Tapatalk 2
Click to expand...
Click to collapse
Haha. :laugh:
Good job. :good:
That was funny lol.
So to recap, Clean your project and restart eclipse. If still doesn't work, delete your project and reimport it.
Cleaing project usualy fixes NoClassDefFound error, if it doest he can also try to restart eclipse and/or reimport project
Sent from my U8120 using Tapatalk 2
pedja1 said:
Code:
class ProblemFixer extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
tryToFixTheProblem();
}
protected void tryToFixTheProblem()
{
try
{
cleanProject();
}
catch(FailedToFixProblemException e)
{
boolean isProblemFixed = new RestartExclipse().execute().getResponse();
if(isProblemFixed)
{
enjoy();
}
else
{
deleteAndReimportProject();
}
}
}
private void deleteAndReimportProject()
{
if(success)
{
enjoy();
}
else
{
finish();
//TODO: Open browser and search for solution;
}
}
}
Sent from my U8120 using Tapatalk 2
Click to expand...
Click to collapse
Can I have the XML for this too?
:laugh:
Your project properties --> Build Path --> Order and Export --> check on Android Private Libraries

[HELP]ProcessDialog

Hi XDA-Developers users!
I'ts easy, how can I make this processdialog visible?
Code:
public void onClick(DialogInterface dialog, int id) {
// metodo que se debe implementar
dialog.cancel();
pd = ProgressDialog.show(FixWifiActivity.this, "dialog title", "dialog message", true);
try {
ProcessBuilder pb = new ProcessBuilder(new String[] { "su", "-c", "/system/bin/reboot" });
java.lang.Process process = pb.start();
process.waitFor();
} catch (IOException e) {
}
// TODO Auto-generated method stub
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} });
AlertDialog alert = builder.create();
alert.show();
}
}
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2
Please...
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2
Come on... It's easy...
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2
Do it like this:
Code:
ProgressDialog pd = new ProgressDialog(context);
pd.setTitle("My title");
pd.setMessage("Operation...");
pd.show();
nikwen said:
Do it like this:
Code:
ProgressDialog pd = new ProgressDialog(context);
pd.setTitle("My title");
pd.setMessage("Operation...");
pd.show();
Click to expand...
Click to collapse
Ok, I'm going to try it
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2
nikwen said:
Do it like this:
Code:
ProgressDialog pd = new ProgressDialog(context);
pd.setTitle("My title");
pd.setMessage("Operation...");
pd.show();
Click to expand...
Click to collapse
No no no, you don't understand me What I mean is that I want to make the ProgressDialog visible becouse the reboot process block it.
Try to make a code that shows the ProcessDialog and then give it to me. Please...
EDIT:
What I want is show a progress dialog while a process is running, I think I need something like asynktask.
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2
alert.show(); does not work?
alert.show(); does not work?
DannyGM16 said:
Hi XDA-Developers users!
I'ts easy, how can I make this processdialog visible?
Code:
public void onClick(DialogInterface dialog, int id) {
// metodo que se debe implementar
dialog.cancel();
pd = ProgressDialog.show(FixWifiActivity.this, "dialog title", "dialog message", true);
try {
ProcessBuilder pb = new ProcessBuilder(new String[] { "su", "-c", "/system/bin/reboot" });
java.lang.Process process = pb.start();
process.waitFor();
} catch (IOException e) {
}
// TODO Auto-generated method stub
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} });
AlertDialog alert = builder.create();
alert.show();
}
}
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2
Click to expand...
Click to collapse
DannyGM16 said:
No no no, you don't understand me What I mean is that I want to make the ProgressDialog visible becouse the reboot process block it.
Try to make a code that shows the ProcessDialog and then give it to me. Please...
EDIT:
What I want is show a progress dialog while a process is running, I think I need something like asynktask.
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2
Click to expand...
Click to collapse
If you want the progress to.continue while doing a background task, your best and easy bet is to use async task. Create and show progress dialog in onPreExecute() and do the task in doInBackground() and close the progress in onPostExecute().
Sent from my GT-N7000 using xda app-developers app
vijai2011 said:
If you want the progress to.continue while doing a background task, your best and easy bet is to use async task. Create and show progress dialog in onPreExecute() and do the task in doInBackground() and close the progress in onPostExecute().
Sent from my GT-N7000 using xda app-developers app
Click to expand...
Click to collapse
Thank's a lot, this is what I mean ;D
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2
vijai2011 said:
If you want the progress to.continue while doing a background task, your best and easy bet is to use async task. Create and show progress dialog in onPreExecute() and do the task in doInBackground() and close the progress in onPostExecute().
Sent from my GT-N7000 using xda app-developers app
Click to expand...
Click to collapse
... can you give me an example code of AsyncTask?, I can't find an understable explanation on Internet (for me)
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2
Here it is with progress dialog
Code:
class MyAsyncTask extends AsyncTask<Void, Void, Void> {
ProgressDialog prog;
[user=439709]@override[/user]
protected void onPreExecute() {
prog = new ProgressDialog(youractivity.this);
prog.setCancelable(false);
prog.setTitle("Title");
prog.setMessage("Message");
prog.setIndeterminate(true);
prog.show();
}
protected Void doInBackground(Void... params) {
//Your task to be done in Background while progress dialog is showing
return null;
}
[user=439709]@override[/user]
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
prog.dismiss(); //Progress is dismissed after background task is done
}
}
vijai2011 said:
Here it is with progress dialog
Code:
class MyAsyncTask extends AsyncTask<Void, Void, Void> {
ProgressDialog prog;
[user=439709]@override[/user]
protected void onPreExecute() {
prog = new ProgressDialog(youractivity.this);
prog.setCancelable(false);
prog.setTitle("Title");
prog.setMessage("Message");
prog.setIndeterminate(true);
prog.show();
}
protected Void doInBackground(Void... params) {
//Your task to be done in Background while progress dialog is showing
return null;
}
[user=439709]@override[/user]
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
prog.dismiss(); //Progress is dismissed after background task is done
}
}
Click to expand...
Click to collapse
Why it does not work?
Code:
public void End() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Es necesario reiniciar")
.setTitle("Instalacion satisfactoria!")
.setCancelable(false)
.setNegativeButton("Hacerlo mas tarde",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.setPositiveButton("Reiniciar",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
class MyAsyncTask extends AsyncTask<Void, Void, Void> {
ProgressDialog prog;
[user=439709]@override[/user]
protected void onPreExecute() {
prog = new ProgressDialog(FixWifiActivity.this);
prog.setCancelable(false);
prog.setTitle("Title");
prog.setMessage("Message");
prog.setIndeterminate(true);
prog.show();
}
protected Void doInBackground(Void... params) {
ProcessBuilder pb = new ProcessBuilder(new String[] { "su", "-c", "/system/bin/reboot" });
java.lang.Process process = pb.start();
process.waitFor();
return null;
}
[user=439709]@override[/user]
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
prog.dismiss();
//Progress is dismissed after background task is done
}
AlertDialog alert = builder.create();
alert.show();
}
It has lots of errors
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2
DannyGM16 said:
Why it does not work?
Code:
public void End() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Es necesario reiniciar")
.setTitle("Instalacion satisfactoria!")
.setCancelable(false)
.setNegativeButton("Hacerlo mas tarde",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.setPositiveButton("Reiniciar",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
class MyAsyncTask extends AsyncTask<Void, Void, Void> {
ProgressDialog prog;
[user=439709]@override[/user]
protected void onPreExecute() {
prog = new ProgressDialog(FixWifiActivity.this);
prog.setCancelable(false);
prog.setTitle("Title");
prog.setMessage("Message");
prog.setIndeterminate(true);
prog.show();
}
protected Void doInBackground(Void... params) {
ProcessBuilder pb = new ProcessBuilder(new String[] { "su", "-c", "/system/bin/reboot" });
java.lang.Process process = pb.start();
process.waitFor();
return null;
}
[user=439709]@override[/user]
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
prog.dismiss();
//Progress is dismissed after background task is done
}
AlertDialog alert = builder.create();
alert.show();
}
It has lots of errors
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2
Click to expand...
Click to collapse
The ide will say of unimplemented method. Just highlight it and add unimplemented method and delete tye auto generated method. It will work then
Sent from my GT-N7000 using xda app-developers app
vijai2011 said:
The ide will say of unimplemented method. Just highlight it and add unimplemented method and delete tye auto generated method. It will work then
Sent from my GT-N7000 using xda app-developers app
Click to expand...
Click to collapse
Sorry, I'm Spanish, be more specific, with examples or something like this... I don't understand you
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2
DannyGM16 said:
Sorry, I'm Spanish, be more specific, with examples or something like this... I don't understand you
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2
Click to expand...
Click to collapse
Take you mouse pointer over AsyncTask which would be underlined in red and click on "Add unimplemented method" or something like that. Then delete the methods having the comment "// TODO Auto-generated method stub". Then the error would be gone.
vijai2011 said:
Take you mouse pointer over AsyncTask which would be underlined in red and click on "Add unimplemented method" or something like that. Then delete the methods having the comment "// TODO Auto-generated method stub". Then the error would be gone.
Click to expand...
Click to collapse
I'm developing with my mobile xD
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2
vijai2011 said:
Take you mouse pointer over AsyncTask which would be underlined in red and click on "Add unimplemented method" or something like that. Then delete the methods having the comment "// TODO Auto-generated method stub". Then the error would be gone.
Click to expand...
Click to collapse
Please, can you give me the code?
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2
DannyGM16 said:
I'm developing with my mobile xD
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2
Click to expand...
Click to collapse
With AIDE? Long-click on the code with the red mark below. Then click the first entry (something like "fix"). Select "add unimplemented methods".
That's it.
nikwen said:
With AIDE? Long-click on the code with the red mark below. Then click the first entry (something like "fix"). Select "add unimplemented methods".
That's it.
Click to expand...
Click to collapse
FU** It doesn't appear :'(
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2
nikwen said:
With AIDE? Long-click on the code with the red mark below. Then click the first entry (something like "fix"). Select "add unimplemented methods".
That's it.
Click to expand...
Click to collapse
Code:
public void onClick(DialogInterface dialog, int id) {}
// metodo que se debe implementar
private class PlantFiles extends AsyncTask {
protected Boolean doInBackground(Void... arg0) {
try
{
comando();
}
catch (InterruptedException e)
{}
catch (IOException e)
{}
return null;
}
private void comando() throws IOException, InterruptedException
{
ProcessBuilder pb = new ProcessBuilder(new String[] { "su", "-c", "/system/bin/reboot" });
java.lang.Process process = pb.start();
process.waitFor();
}
protected void onPostExecute(Boolean result){
pd.cancel();
}
protected void onPreExecute(Boolean result){
pd = ProgressDialog.show(FixWifiActivity.this, "Wait", "Loading...", true);
}
}});
AlertDialog alert = builder.create();
alert.show();
}
}
The code is correct but It doesn't work, can you fix it?
Enviado desde mi Galaxy Mini Plus 4G usando Tapatalk 2

How to implement mp3 tags editor in apk?

Hi,
I'm a newbie developer and I thought that I want to add the ability to edit tags in music files (id3 tags),but I have no idea how to do that. Could somebody point me to a guide or explain me how that could be done? With parts of code if possible please.
Thanks.
Wysłane z mojego C6903 przy użyciu Tapatalka
olokos said:
Hi,
I'm a newbie developer and I thought that I want to add the ability to edit tags in music files (id3 tags),but I have no idea how to do that. Could somebody point me to a guide or explain me how that could be done? With parts of code if possible please.
Thanks.
Wysłane z mojego C6903 przy użyciu Tapatalka
Click to expand...
Click to collapse
You have to download this file: https://sites.google.com/site/eternalsandbox/myid3-for-android
Then, add it to your project as reference.
The code is this: (pathdata) is the path of your audio file
Code:
File src = new File(pathdata);
MusicMetadataSet src_set = null;
try {
src_set = new MyID3().read(src);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} // read metadata
if (src_set == null) // perhaps no metadata
{
Log.i("NULL", "NULL");
}
else
{
try{
IMusicMetadata metadata = src_set.getSimplified();
String artist = metadata.getArtist();
String album = metadata.getAlbum();
String song_title = metadata.getSongTitle();
Number track_number = metadata.getTrackNumber();
Log.i("artist", artist);
Log.i("album", album);
}catch (Exception e) {
e.printStackTrace();
}
File dst = new File(pathdata);
MusicMetadata meta = new MusicMetadata("name");
meta.setAlbum("Chirag");
meta.setArtist("CS");
try {
new MyID3().write(src, dst, src_set, meta);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ID3WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // write updated metadata
Hope it's useful!
Jeeko said:
You have to download this file: https://sites.google.com/site/eternalsandbox/myid3-for-android
Then, add it to your project as reference.
The code is this: (pathdata) is the path of your audio file
Code:
File src = new File(pathdata);
MusicMetadataSet src_set = null;
try {
src_set = new MyID3().read(src);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} // read metadata
if (src_set == null) // perhaps no metadata
{
Log.i("NULL", "NULL");
}
else
{
try{
IMusicMetadata metadata = src_set.getSimplified();
String artist = metadata.getArtist();
String album = metadata.getAlbum();
String song_title = metadata.getSongTitle();
Number track_number = metadata.getTrackNumber();
Log.i("artist", artist);
Log.i("album", album);
}catch (Exception e) {
e.printStackTrace();
}
File dst = new File(pathdata);
MusicMetadata meta = new MusicMetadata("name");
meta.setAlbum("Chirag");
meta.setArtist("CS");
try {
new MyID3().write(src, dst, src_set, meta);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ID3WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // write updated metadata
Hope it's useful!
Click to expand...
Click to collapse
Thank you mate.
I can't find in this code a popup with sth like "type in the Artist" etc...
What do I have to do with the pathname?
How do I entirely implement it in my music player?
I'm still a newb, excuse me that.
olokos said:
Thank you mate.
I can't find in this code a popup with sth like "type in the Artist" etc...
What do I have to do with the pathname?
How do I entirely implement it in my music player?
I'm still a newb, excuse me that.
Click to expand...
Click to collapse
This link can be very useful https://java.net/projects/jaudiotagger/
Anyway, you have to implement this code into your "audio editing" activity,
basically the one that have the show.audioinfo function.
The popup is already included in the library, you have only to call that
with a code lik this
Code:
Mp3File mp3file = new Mp3File("SomeMp3File.mp3");
ID3v1 id3v1Tag;
if (mp3file.hasId3v1Tag()) {
id3v1Tag = mp3file.getId3v1Tag();
} else {
// mp3 does not have an ID3v1 tag, let's create one..
id3v1Tag = new ID3v1Tag();
mp3file.setId3v1Tag(id3v1Tag);
}
id3v1Tag.setTrack("5");
id3v1Tag.setArtist("An Artist");
id3v1Tag.setTitle("The Title");
id3v1Tag.setAlbum("The Album");
id3v1Tag.setYear("2001");
id3v1Tag.setGenre(12);
id3v1Tag.setComment("Some comment");
mp3file.save("MyMp3File.mp3");
Want some real confirm? https://github.com/mpatric/mp3agic this is the ID3 guru
Thanks. After I finish something else I'll post here again if I'd have any further questions.
Wysłane z mojego C6903 przy użyciu Tapatalka

Replace substring from inputText

Hello all
i'm newbie
i just want to ask..
how to replace substring from textinput/input text?
this is my code
public void ngeji(EditText editText){
EditText editteks = (EditText) findViewById(R.id.editText1);
String str = editteks.getText().toString();
if(str!= null){
str.toUpperCase();
str.replaceAll("U", "OO");
str.replaceAll("C", "TJ");
str.replaceAll("F", "EV");
str.replaceAll("ES", "X");
str.replaceAll("EKS", "X");
editText.setText(str);}
}
public void normalin(EditText editText){
EditText editteks = (EditText) findViewById(R.id.editText2);
String str = editteks.getText().toString();
if(str!=null){
str.toLowerCase();
str.replaceAll("oo", "u");
str.replaceAll("tj", "c");
str.replaceAll("ev", "f");
str.replaceAll("x", "eks");
str.replaceAll("y", "i");
str.replaceAll("q", "k");
editText.setText(str);
}
}
what's wrong with the code?
btw i just wanna make translator...its like ticky word translator
for example
i = OO
j = DJ
and Uppercase all
when i type : juanda
so... the result is DJOOANDA
i'll wait for your reply
thanks
Both .toUpperCase() and .replaceAll() return a string - they do not affect the string that you run them against. So this will do nothing...
Code:
str.toUpperCase();
str.replaceAll("U", "OO");
str.replaceAll("C", "TJ");
str.replaceAll("F", "EV");
str.replaceAll("ES", "X");
str.replaceAll("EKS", "X");
This is what you want...
Code:
str = str.toUpperCase();
str = str.replaceAll("U", "OO");
str = str.replaceAll("C", "TJ");
str = str.replaceAll("F", "EV");
str = str.replaceAll("ES", "X");
str = str.replaceAll("EKS", "X");
Archer said:
Both .toUpperCase() and .replaceAll() return a string - they do not affect the string that you run them against. So this will do nothing...
Code:
str.toUpperCase();
str.replaceAll("U", "OO");
str.replaceAll("C", "TJ");
str.replaceAll("F", "EV");
str.replaceAll("ES", "X");
str.replaceAll("EKS", "X");
This is what you want...
Code:
str = str.toUpperCase();
str = str.replaceAll("U", "OO");
str = str.replaceAll("C", "TJ");
str = str.replaceAll("F", "EV");
str = str.replaceAll("ES", "X");
str = str.replaceAll("EKS", "X");
Click to expand...
Click to collapse
Thanks for the solution , but i'm still stuck in the error...maybe i have a wrong code
can you fix up my code?
this is my code
Code:
package com.example.qdjytranslator;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.EditText;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void ngeji(EditText editText){
EditText editteks = (EditText) findViewById(R.id.editText1);
String str = editteks.getText().toString();
if(str!= null){
str = str.toUpperCase();
str = str.replace("U", "OO");
str = str.replace("C", "TJ");
str = str.replace("F", "EV");
str = str.replace("ES", "X");
str = str.replace("EKS", "X");
editText.setText(str);
}
}
public void normalin(EditText editText){
EditText editteks = (EditText) findViewById(R.id.editText2);
String str = editteks.getText().toString();
if(str!=null){
str = str.toLowerCase();
str = str.replace("oo", "u");
str = str.replace("tj", "c");
str = str.replace("ev", "f");
str = str.replace("x", "eks");
editText.setText(str);
}
}
public void onTerminate()
{
super.onDestroy();
this.finish();
}
@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'll waiting for your reply
Where do you call these methods ?
Code:
ngeji(EditText editText)
normalin(EditText editText)
fikriakhdi said:
Thanks for the solution , but i'm still stuck in the error...maybe i have a wrong code
can you fix up my code?
Click to expand...
Click to collapse
LinuxForce said:
Where do you call these methods ?
Code:
ngeji(EditText editText)
normalin(EditText editText)
Click to expand...
Click to collapse
^^ This, and what errors do you have?
Why are you using an edittext as an input for both functions when you are not using it.just leave brackets empty
public void function()
{
}
Sent from my GT-S5570 using XDA Premium 4 mobile app

Categories

Resources