Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: how do I rewrite this program to android program? and what am I doing wrong ?

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how do I rewrite this program to android program? and what am I doing wrong ?

    Hello everyone.

    I have this code in java, and I tired to convert it to android, but it dose won't to work:

     
    public ShopPhone() {
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setBounds(100, 100, 450, 300);
    		contentPane = new JPanel();
    		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    		contentPane.setLayout(new BorderLayout(0, 0));
    		setContentPane(contentPane);
     
    		tF = new JTextField();
    		contentPane.add(tF, BorderLayout.NORTH);
    		tF.setColumns(10);
    		tF.setText("");
     
     
    		JButton btnNewButton = new JButton("New button");
    		btnNewButton.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
     
     
    				if(tF.getText().equals("x")){
     
    					x = "5733689997";
     
    				}
    				 JOptionPane.showMessageDialog(null, x);
    			}
    		});
    		contentPane.add(btnNewButton, BorderLayout.SOUTH);
    	}
     
    }


    and this my code for the android:

     
    public class MainActivity extends ActionBarActivity {
     
    	public EditText search;
    	public TextView print;
    	public Button bFind;
     
    	protected String name;
     
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);
     
    		if (savedInstanceState == null) {
    			getSupportFragmentManager().beginTransaction()
    					.add(R.id.container, new PlaceholderFragment()).commit();
    		}
     
     
    		search = (EditText) findViewById(R.id.find);
    		print = (TextView) findViewById(R.id.show);
    		bFind = (Button) findViewById(R.id.press);
    		bFind.setOnClickListener(new OnClickListener() {
     
    			@Override
    			public void onClick(View v) {
     
    				if(search.getText().equals("name")){
     
    					name = "horyah";
    				}			
    				print.setText(name);
    			}
     
    		});
     
    	}

    can anyone tell me what am I doing wrong. please help

    Thank you.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how do I rewrite this program to android program? and what am I doing wrong ?

    what am I doing wrong
    Please explain.
    If you get error messages, copy the full text and paste it here.
    If the program executes differently than you want, explain what it does and what you want it to do.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how do I rewrite this program to android program? and what am I doing wrong ?

    Quote Originally Posted by Norm View Post
    Please explain.
    If you get error messages, copy the full text and paste it here.
    If the program executes differently than you want, explain what it does and what you want it to do.
    I don't get an error, but one I press on the button ( Find ) it won't show the name or do anything

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how do I rewrite this program to android program? and what am I doing wrong ?

    Is the listener called? Add a call to println() to the listener to see if it is called. Print out the value of name for example. The output will show in the LogCat window.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2014
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how do I rewrite this program to android program? and what am I doing wrong ?

    Quote Originally Posted by Norm View Post
    Is the listener called? Add a call to println() to the listener to see if it is called. Print out the value of name for example. The output will show in the LogCat window.
    I'm sorry I did not understand what do you mean. what I'm trying to do is a searching box. For example; in basic java it work fine.

    Look at this code:




    if(tF.getText().equals("x1")){

    x1 = "5733689997";

    }

    if(tF.getText().equals("x2")){

    x2 = "123456789";

    }

    if( x1 == null){

    x1 = "";
    }

    if( x2 == null){

    x2 = "";
    }

    JOptionPane.showMessageDialog(null, x1 + x2);

    x1 = "";
    x2 = "";


  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how do I rewrite this program to android program? and what am I doing wrong ?

    Please wrap the code in code tags not in quote tags.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Jan 2014
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how do I rewrite this program to android program? and what am I doing wrong ?

    Quote Originally Posted by Norm View Post
    Please wrap the code in code tags not in quote tags.
    sorry, here you go

     
    if(tF.getText().equals("x1")){
     
    x1 = "5733689997";
     
    }
     
    if(tF.getText().equals("x2")){
     
    x2 = "123456789";
     
    }
     
    if( x1 == null){
     
    x1 = "";
    }
     
    if( x2 == null){
     
    x2 = "";
    }
     
    JOptionPane.showMessageDialog(null, x1 + x2);
     
    x1 = "";
    x2 = "";

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how do I rewrite this program to android program? and what am I doing wrong ?

    The code has lost all of its formatting and indentations.

    Why are you posting this simple bit of code?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Jan 2014
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how do I rewrite this program to android program? and what am I doing wrong ?

    Quote Originally Posted by Norm View Post
    The code has lost all of its formatting and indentations.

    Why are you posting this simple bit of code?
    will this not the real code for the android programming as I said before. It's just an example in basic java, and this code is working, but what I really want is making a search box in android Similar or may be different in code to what I wrote in basic java

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how do I rewrite this program to android program? and what am I doing wrong ?

    There are several ways to present a "dialog window" where a question can be asked and a response received.
    I've often found lots of code examples by doing a search on the internet.

    There aren't too many experienced Android programmers on this forum. I've written a few apps but not enough .
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. What do I need to know to program this in Android?
    By rememberMe in forum Android Development
    Replies: 2
    Last Post: January 27th, 2014, 10:21 AM
  2. Connecting Android and PC for Speaking together in My own program
    By Navid Noorani in forum What's Wrong With My Code?
    Replies: 0
    Last Post: September 14th, 2013, 07:47 AM
  3. Seeking Developer To Port Our Program To Android!
    By cdenczek in forum Android Development
    Replies: 0
    Last Post: August 28th, 2013, 01:48 AM
  4. [SOLVED] Installed Android program which I created bombs out
    By HanneSThEGreaT in forum What's Wrong With My Code?
    Replies: 20
    Last Post: July 12th, 2013, 04:40 AM
  5. xml view for android program
    By ikkyu in forum Java IDEs
    Replies: 0
    Last Post: November 28th, 2011, 10:27 PM