0

I am developing a weather app like S4 weather app. This app also has a digital clock with it. I want to make other widget for digital clock in the same project and then add that widget to main widget. Hope you get the point. Here'the image link of what i am doing

Since this is my first project i am getting confused on how to add the clock widget in the main widget.

My activity_main.xml
<LinearLayout>
     //some stuff 
            <com.itcse.weather.DigitalClock
                xmlns:android="http://schemas.android.com/apk/res/android" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/digitalClock" />
    // some stuff
</LinearLayout>

The GraphicalLayout of the activity_main.xml is showing

The following classes could not be instantiated:
- com.itcse.weather.DigitalClock

which i know it should show since i haven't initialized the class anywhere. But i am getting confused in how to do it.

At present i have not done any coding in DigitalClock.java, simply set default layout in AppwidgetProvider. When i run the project on emulator i am getting a new widget of digital clock as option thus that means it is working.

I know i have to initialize DigitalClock Class in my AppWidgetProvider Configure but I am getting confused in how to do so.

I am using a DigitalClock separately since that is my custon digital clock and would need to set update period as 0. It would be unnecessary to set the update time of main widget as 0 so i am using this widget. Is this way right?

Also i want to ask something that when i finish this project can i upload it here and ask for some suggestions on what should i have actually done. Since this is my first project so i have done a lot of hit and trial and i don't know if i can do this, so i am asking you. Is this allowed??

UPDATE:- I think i am not making myself clear. Consider that i am making two seperate widgets in my same project. One is DigitalClock which has time and date. Another is main widget which has weather plus time and date. Now i want that to use DigitalClock in place of time and date in main widget. I have declared both widgets seperatly in manifest and they both are working correctly seperatly. Is this possible?

Rohan Kandwal
  • 9,112
  • 8
  • 74
  • 107
  • `DigitalClock` class `extends` what? – yugidroid Jun 21 '13 at 14:10
  • @yugidroid `AppWidgetProvider` since it is a widget as i mentioned earlier – Rohan Kandwal Jun 21 '13 at 14:13
  • AppWidgetProvider is not a View subclass – viplezer Jun 21 '13 at 14:15
  • Take a look at this doc http://developer.android.com/guide/topics/appwidgets/index.html. `AppWidgetProvider` class is declared at the manifest not in xml layout file. You can only use at the xml some class extending `View`. – yugidroid Jun 21 '13 at 14:16
  • @coelho that means i cannot implement one widget in another?? – Rohan Kandwal Jun 21 '13 at 14:16
  • @yugidroid i have declared digitalClock class in manifest as widget. I know it is to be implemented that way. As i told earlier DigitalClock is appearing as an additional widget on emulator so i know i did that part right. Please look at the link of the image i provided. The area in the red eclipse is what that DigitalClock widget is. Now i want to add that part in my main widget xml. did you understand what i am asking? – Rohan Kandwal Jun 21 '13 at 14:20
  • That means what @yugidroid said (addition: in layout xmls) – viplezer Jun 21 '13 at 14:21
  • @coelho sorry i didn't get you. I am updating the question may be i am not asking correctly. – Rohan Kandwal Jun 21 '13 at 14:23
  • @RohanKandwal, I understand now! I'm afraid you can't do that. Why don't you use the `DigitalClock` to edit as you want it or get some code from there to your proj. (Remember to look to the license first) – yugidroid Jun 21 '13 at 14:25
  • @yugidroid Should i use `DigitalClock` as an activity and then use it in my `main widget`? I think implementing a clock in same View thread of main widget will consume more memory and make it slow. What should i do? give me your suggestions. – Rohan Kandwal Jun 21 '13 at 14:35
  • You can only use View subclasses in layout xml's. If DigitalClock is just an AppWidgetProvider subclass, you can't use it. If it was a View subclass, you could use it like you wrote in your xml. If you only want to include the digital clock's layout in your new layout, you can use the include tag http://developer.android.com/training/improving-layouts/reusing-layouts.html#Include in your xml. If none of these what you want, I don't get your question, sorry :S – viplezer Jun 21 '13 at 14:38
  • @coelho Actually the whole idea is to implement a digital clock with a date as shown in the image. The hours and seconds are labeled using images instead of text i.e image for every integer in time as well as for AM and PM. Since widget inside another widget is not possible how should i do it? – Rohan Kandwal Jun 21 '13 at 14:46
  • I would write a custom View for this. – viplezer Jun 21 '13 at 14:49
  • @coelho like in this question? http://stackoverflow.com/questions/7610549/android-digitalclock-remove-seconds – Rohan Kandwal Jun 21 '13 at 14:52

0 Answers0