IJET's Profile User Rating: -----

Reputation: 93 Whiz
Group:
Contributors
Active Posts:
122 (0.18 per day)
Joined:
14-October 12
Profile Views:
31,644
Last Active:
User is offline Dec 18 2013 01:02 AM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
FireFox
Favorite Processor:
Intel
Favorite Gaming Platform:
Playstation
Your Car:
Who Cares
Dream Kudos:
100

Latest Visitors

Icon   IJET has not set their status

Posts I've Made

  1. In Topic: Start Activity For Result ?

    Posted 15 Jun 2013

    Well, textV isn't a TextView, it's an EditText. You need to change that.

    I put the x.getText() value inside of the button that way it pulls the value once the button is clicked. If you set it on start up, it won't be equal to anything.

    Here is something that should work:

    package com.example.exampleapp;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.onclickListener;
    import android.widget.Button;
    import android.widget.TextView;
    
    public class ActivityTwo extends Activity{
    
    
    	String password = "password";
            String x;
    	
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.secondscreen);
    		
    		
    	
    		
    		Button btn_2 = (Button)findViewById(R.id.button_2);
    			EditText textV = (EditText)findViewById(R.id.et_View);
    
    		btn_2.setonclickListener(new onclickListener(){
    			 
    			 
    		
    				
    			public void onclick(View view){
    				x = textV.getText().toString();
    				if(x.equals(password)){
    			    
    				startActivity(new Intent(ActivityTwo.this, ActivityThree.class)); 
    				
    				}
    				
    				
    			}
    		});
    		
    		
    		
    		
    		
    
    	}	
    
    }
    
    
    
  2. In Topic: JavaScript File Not Working

    Posted 12 Jun 2013

    Well, you aren't referencing a JQuery library anywhere in your files from what I can see. You can download it and reference it locally or use Google as the host and include something like the following:

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
    </script>
    
  3. In Topic: Accessing Layout Elements Outside Activity

    Posted 4 Jun 2013

    Well, as I cannot see your code, I am not able to understand exactly what your problem is. I will post a couple examples of how to change the text by calling a method from another class:

    Example 1:

    Buttonclick.Java:

    public void doSomething(TextView v){
    		
    		
    		v.setText("Hello");
    	}
    
    


    MainActivity.Java

    public class MainActivity extends Activity implements onclickListener {
    
    	Button button;
    	buttonclick bc;
    	TextView tv;
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);
    		bc =  new buttonclick();
    		tv = (TextView)findViewById(R.id.textView1);
    		button = (Button)findViewById(R.id.button1);
    		button.setonclickListener(this);
    		
    	}
    	@Override
    	public void onclick(View v) {
    		switch(v.getId()){
    		case R.id.button1:
    			bc.doSomething(tv);
    			break;
    		}
    		
    	}
    
    	
    	
    }
    
    


    Example 2:

    Buttonclick.Java

    public class buttonclick implements onclickListener {
    	
    	TextView tv;
    	
    	public buttonclick(TextView t){
    		tv = t;
    	}
    	
    	@Override
    	public void onclick(View v) {
    		tv.setText("Hello!");
    		
    	}
    
    
    
    
    }
    
    


    MainActivity.Java:

    public class MainActivity extends Activity {
    
    	Button button;
    	TextView tv;
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);
    		tv = (TextView)findViewById(R.id.textView1);
    		button = (Button)findViewById(R.id.button1);
    		button.setonclickListener(new buttonclick(tv));
    		
    	}
    
    
    	
    	
    }
    


    The above examples are rather simple and showcase a few different ways to pull off changing the text. In the first, just passing a TextView reference "tv" that is tied to a TextView in the layout through the method doSomething in the buttonclick class. The second example is pretty self explanatory after seeing the first. Not all sure what else you're trying to change, just see you mentioned setting text values so this should push you in the right direction.
  4. In Topic: Accessing Layout Elements Outside Activity

    Posted 4 Jun 2013

    Hey.

    I'm doing my best to try and understand your code. It would seem you're just wanting to swap-in and out layouts, right?

    Quote

    I'm writing an app right now, and the way I implement different "pages" or layouts in the app is by using different classes for each. I pass the main Activity into each class's constructor, and use that from there to use findViewById and in each class I set the onclickListeners for each button and I also set some the values of each view.


    You really need to be using fragments to do this. If you're unaware of how fragments work, here is a quick link to get you started(there's a lot of tutorials out there if need be). They will allow you to load in new layouts & functionality very easily and it's the correct way. They're the preferred method for doing what you're doing and it's common practice that one should always use them when designing UIs. For an example of their magic: a single activity will run that can host a fragment that inflates a layout. Great, after it's inflated now you want a new layout. The activity stays running, but you swap out the previous fragment for the new fragment. On large screens, you can run two fragments inside of one activity displaying two UIs at once. There's NO limit to how many fragments you can swap in and out.

    Quote

    However, after testing my app, I realized that if I set the onclickListener from another class that is not the Main Activity, it just doesn't process. I'm not really sure why this would be,


    I guess this part is kind of confusing to me. The Main Activity will be looking within itself for functionality. I don't know that there is a way to do what you're doing as fragments are the correct way to handle these things.
  5. In Topic: Signature of the Month: June 2013

    Posted 1 Jun 2013

    Haven't been around for a bit and missed quite a few of these. Here's my submission for this month:

    Posted Image

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Years Programming:
6
Programming Languages:
C++, C#, Java, HTML/CSS, JavaScript/Jquery, SQL

Contact Information

E-mail:
Private

Friends

IJET hasn't added any friends yet.

Comments

IJET has no profile comments yet. Why not say hello?