|
Hi!I have in MainActivity textView,whole show contents files (which located in the folder). I need show contents next file (which located in the folder) when click on button. I hope the problem is clear)))
Thanks in advance.
P.S. Now code looks like this:
TextView myTv;
String res = "";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.universal);
myTv = (TextView) findViewById(R.id.textView);
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
getAssets().open("universal")));
String myLine = reader.readLine();
while (myLine != null) {
res += myLine + "\n";
myLine = reader.readLine();
}
reader.close();
} catch (IOException e) {
Toast.makeText(getApplicationContext(),
"Error Opening the File !!!", Toast.LENGTH_LONG).show();
}
myTv.setText(res);
modified 11-Nov-14 10:44am.
|
|
|
|
|
Kroshandowski wrote: P.S. Now code looks like this: But what's the problem? Be specific. Have you stepped through the code using the debugger?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi All;
Please help as I am going nuts.
Whenever I start a new application I always run it 'naked' just to confirm that everything is ok. From this afternoon all applications I create are coming up with the error as in the logcat dump below. As far as I can see the activity_main.xml file is correct and there is only this one form in the project.
All old applications run ok without hiccups.
Any help appreciated.
Regards
Eric
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.mysecondapp.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
LogCat Dump
10-30 17:36:54.762: I/dalvikvm(1792): Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
10-30 17:36:54.762: W/dalvikvm(1792): VFY: unable to resolve virtual method 11378: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
10-30 17:36:54.762: D/dalvikvm(1792): VFY: replacing opcode 0x6f at 0x0000
10-30 17:36:54.772: I/dalvikvm(1792): Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
10-30 17:36:54.772: W/dalvikvm(1792): VFY: unable to resolve virtual method 11384: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
10-30 17:36:54.772: D/dalvikvm(1792): VFY: replacing opcode 0x6f at 0x0000
10-30 17:36:54.782: I/dalvikvm(1792): Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
10-30 17:36:54.782: W/dalvikvm(1792): VFY: unable to resolve virtual method 8957: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
10-30 17:36:54.782: D/dalvikvm(1792): VFY: replacing opcode 0x6e at 0x000e
10-30 17:36:54.792: D/AndroidRuntime(1792): Shutting down VM
10-30 17:36:54.792: W/dalvikvm(1792): threadid=1: thread exiting with uncaught exception (group=0xb2b10ba8)
10-30 17:36:54.812: E/AndroidRuntime(1792): FATAL EXCEPTION: main
10-30 17:36:54.812: E/AndroidRuntime(1792): Process: com.example.mysecondapp, PID: 1792
10-30 17:36:54.812: E/AndroidRuntime(1792): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mysecondapp/com.example.mysecondapp.MainActivity}: java.lang.RuntimeException: Binary XML file line #27: You must supply a layout_width attribute.
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.app.ActivityThread.access$800(ActivityThread.java:135)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.os.Handler.dispatchMessage(Handler.java:102)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.os.Looper.loop(Looper.java:136)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.app.ActivityThread.main(ActivityThread.java:5017)
10-30 17:36:54.812: E/AndroidRuntime(1792): at java.lang.reflect.Method.invokeNative(Native Method)
10-30 17:36:54.812: E/AndroidRuntime(1792): at java.lang.reflect.Method.invoke(Method.java:515)
10-30 17:36:54.812: E/AndroidRuntime(1792): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
10-30 17:36:54.812: E/AndroidRuntime(1792): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
10-30 17:36:54.812: E/AndroidRuntime(1792): at dalvik.system.NativeStart.main(Native Method)
10-30 17:36:54.812: E/AndroidRuntime(1792): Caused by: java.lang.RuntimeException: Binary XML file line #27: You must supply a layout_width attribute.
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:492)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:5948)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:6117)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.support.v7.internal.widget.ActionBarOverlayLayout$LayoutParams.<init>(ActionBarOverlayLayout.java:801)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.support.v7.internal.widget.ActionBarOverlayLayout.generateLayoutParams(ActionBarOverlayLayout.java:353)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.support.v7.internal.widget.ActionBarOverlayLayout.generateLayoutParams(ActionBarOverlayLayout.java:50)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.view.LayoutInflater.rInflate(LayoutInflater.java:757)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:273)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:225)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
10-30 17:36:54.812: E/AndroidRuntime(1792): at com.example.mysecondapp.MainActivity.onCreate(MainActivity.java:13)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.app.Activity.performCreate(Activity.java:5231)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-30 17:36:54.812: E/AndroidRuntime(1792): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
10-30 17:36:54.812: E/AndroidRuntime(1792): ... 11 more
10-30 17:36:57.842: I/Process(1792): Sending signal. PID: 1792 SIG: 9
modified 6-Nov-14 6:02am.
|
|
|
|
|
In your RelativeLayout section try substituting "match_parent" with "wrap_content"
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
|
|
|
|
|
Hi Dominic;
Thanks for your reply. I will try it out.
Sorry did not reply earlier. I was sick.
Eric
|
|
|
|
|
I have "match_parent" in mine and it works fine.
|
|
|
|
|
Are you using Eclipse or Android Studio? If the former, are there any syntax errors (red X on the left side) with that XML file?
Also, should tools:context be "com.example.mysecondapp.MainActivity" instead?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
modified 3-Nov-14 23:08pm.
|
|
|
|
|
I use Android Developer Tools which is basically Eclipse from what I can understand.
|
|
|
|
|
I think David's second suggestion may be worth looking at.
|
|
|
|
|
hi
how can i record screen in android?
for example i want to record all user activity in screen such as playing movie or read sms or ..., i want to the code(app) record all activity in video format
thank you all
|
|
|
|
|
|
Hi all;
I must start this discussion with three statements.
(a) I am one of those who learns by doing
(b) I have a basic understanding of Android programming
(c) I am a .NET developer (ie: I know how to program).
What I seek is advise on how to go about developing an application I have in mind. This application will be running in the background (therefore a Service) periodically polling a URL to check for new messages. If a new message is found, a notification or toast is displayed. So far, so good. I think I know how to do all that. The service will start automatically at device boot up. This, I think, I have also found how to do.
The problem I have is that as part of the same application I want a UI which the user can then use to process the received message/s. How do I go about implementing this within the same app.
The aim is to have ONE installation package.
I do not think what I seek is rocket science. I would appreciate any notes or links to relevant guides or tutorials.
Regards
Eric
|
|
|
|
|
|
|
I'm not entirely clear what your question relates to. Are you asking how to build the UI or how to process the received messages? Can you clarify what you need help with. What are you trying to achieve?
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
|
|
|
|
|
Hi Dominic;
What I need to know is how to build ONE application that starts automatically as a service, but has a UI which the user will use when the service raises a notification. Which activity will have broadcast, be a broadcast receiver, etc....
Thanks
Eric
|
|
|
|
|
Create an Android Application project, register a Broadcast Receiver with action android.intent.action.BOOT_COMPLETED in the Manifest file.
<receiver android:name=".MyReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Then start the Service from the onReceive() method of the Broadcast Receiver.
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, MyService.class);
context.startService(i);
}
}
Create an Activity with the desired UI and pass that Activity as Pending Intent to the notification.
Intent intent = new Intent(this, MyActivity.class);
PendingIntent launchIntent = PendingIntent.getActivity(context, 0, intent, 0);
When the user taps on the Notification, the Activity used to create the PendingIntent is started.
P.S. - You can have Service, BroadcastReceiver and Activities all in one project.
modified 27-Oct-14 14:11pm.
|
|
|
|
|
I've done something similar that may give you some ideas.
The application I worked on previously polled for updates from a web service. The class that did this background polling was based on the Service class. When a data update was detected from the web service, it would populate the database with the new data.
Do you know what your trigger is? You mentioned that you are polling a URL? Are you polling a web service for updates then? How do you know when you need to trigger your UI?
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
|
|
|
|
|
Hi;
The trigger will be a field in the data received from the webservice. When a trigger is received, a notification/toast will be displayed and then it is up to the user when to open the UI to check the full details what was received. Like the GMail app: you are notified when an email is received but you decide when to open the app to read the email. That part I have it sorted and planned and is something I had implemented on Windows Mobile (in another life).
What I need to know are the steps (and Objects to inherit from) required to do it in Android. My mind is not yet clear about the intents/broadcasts/etc....
Thanks again.
Eric
|
|
|
|
|
Presumably then when the user sees that they have a new notification, they open your app to view the details. So it should just be a case of invoking your UI and displaying the most recent notification. Maybe you could add a flag so you know which notifications have been opened / read, and highlight those in some way.
I'm not sure what data you are displaying, but maybe you could display your data in a grid format, in which case you'd need to define an Adapter. I wrote an article about Android adapters that you may find useful Displaying Data with an Adapter in Xamarin.Android and Visual Studio[^]
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
|
|
|
|
|
Hi Dominc
That is Xamarin. I am trying to keep to Java and basic Android for now.
Thanks
Eric
|
|
|
|
|
I know you are using Java but the classes / objects are the same. Only the syntax is different, but Java and C# are similar enough that you should be able to leverage my example code into your own application.
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
|
|
|
|
|
Ah! Then I must say thank you.
Eric
|
|
|
|
|
|
Hy !
Im working on a tic tac toe game ..
when i press a button I check if the button is free if is free i set the buttons backround to an X.. with :
btn.setBackgroundResource(R.drawable.xpic);
afther this i call a method wich is the "Computer Turns" methot .. now my question is :
Is there any solution to set the picture bifore the mobile phone reach to en of code in "OnClick" ?
for example:
btn.setBackgroundResource(R.drawable.xdraw);
if(checkifwinner()) return;
turn++;
computerTurm();
there is a lot of code in the checkifwinner() because if wins then comes up a dialog.. and i dont want to wait till the dialog pups up.. how can i resolve this problem ?
Thanks a Lot.
|
|
|
|