Trying to put java code into Eclipse, to make android app? -
ok being bombarded bunch of little red x's. using eclipse program create android application. there 2 main files im using. java , xml.
now when making android appplication, have xml file of text boxes, buttons, etc. in it.
the problem java code written receive , print out command prompt. how can implement app/xml file, make print out text boxes,and receive user input(the scanner) text boxes inside actual app? thank much, im brand new @ programming , have been learning java haven't discovered how use it.
this code convert date julian day. works fine. here java file:
import java.util.scanner; class joe { public static void main(string args[]){ scanner jim = new scanner(system.in); int month, day; int answer; system.out.println("enter month: "); month = jim.nextint(); system.out.println("enter day"); day = jim.nextint(); if (month == 1){ answer = (0 + day); system.out.println(answer); }else if (month == 2){ answer = (31 + day); system.out.println(answer); }else if (month == 3){ answer = (59 + day); system.out.println(answer); }else if (month == 4){ answer = (90 + day); system.out.println(answer); }else if (month == 5){ answer = (120 + day); system.out.println(answer); }else if (month == 6){ answer = (151 + day); system.out.println(answer); }else if (month == 7){ answer = (181 + day); system.out.println(answer); }else if (month == 8){ answer = (212 + day); system.out.println(answer); }else if (month == 9){ answer = (243 + day); system.out.println(answer); }else if (month == 10){ answer = (273 + day); system.out.println(answer); }else if (month == 11){ answer = (304 + day); system.out.println(answer); }else if (month == 12){ answer = (334 + day); system.out.println(answer); } } }
and here xml file:
<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.change.juliandayconverter.mainactivity" > <edittext android:id="@+id/edittext3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:ems="10" android:hint="@string/_4_25_2015" android:inputtype="date" > <requestfocus android:layout_width="match_parent" /> </edittext> <edittext android:id="@+id/edittext2" android:layout_width="115dp" android:layout_height="50dp" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_margintop="55dp" android:ems="10" android:inputtype="none|number" /> <textview android:id="@+id/textview1" android:layout_width="200dp" android:layout_height="50dp" android:layout_alignend="@+id/edittext2" android:layout_alignleft="@+id/edittext3" android:layout_alignright="@+id/edittext3" android:layout_below="@+id/edittext3" android:text="please enter date above" android:textstyle="bold|italic" /> </relativelayout>
get adt plugin eclipse, , download sdk android. in eclipse window=>preference=> choose path sdk , u ready start android application. project=>new=>new android application project. there bunch of other things know well. without adt , sdk u cannot make app android.
if u dont eclipse , adt go android studio.
small program gets data , displays same. might you.
mainactivity class:
package com.dj.test; import android.app.activity; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.edittext; import android.widget.textview; public class mainactivity extends activity { textview tvres; edittext etdata; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); //initializing edit text using id in xml file(stored in r.java class). etdata = (edittext) findviewbyid(r.id.editdata); //initializing text view using id given in xml file(stored in r.java class). tvres = (textview) findviewbyid(r.id.tvdisplay); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } public void display(view v){ //when button clicked fetch data edit text , display on text view tvres.settext(etdata.gettext().tostring()); } } 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.dj.test.mainactivity" > <textview android:id="@+id/tvdisplay" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:layout_centerhorizontal="true" android:textsize="25sp"/> <edittext android:id="@+id/editdata" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tvdisplay" android:layout_centerhorizontal="true" android:layout_margintop="80dp" android:hint="enter name"> <requestfocus /> </edittext> <button android:id="@+id/btndisplay" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:text="button" android:onclick="display"/> </relativelayout>
Comments
Post a Comment