TextView and scale - java

I use this code
TextView.animate().setDuration(0).scaleX(scale).scaleY(scale).start();
When scale value increase to some point, it make TextView disappear. I dont know why, and how to prevent it?
[Edit] Attach my test code
[test_text_scale.xml] It is Layout xml file for TestTextScale.java
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:orientation="vertical">
<TextView
android:id="#+id/tv_test_scale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Test" />
<Button
android:id="#+id/bt_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toEndOf="#+id/bt_down"
android:layout_toRightOf="#+id/bt_down"
android:text="Up" />
<Button
android:id="#+id/bt_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="Down" />
</RelativeLayout>
[TestTextScale.java]
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class TestTextScale extends AppCompatActivity {
// View
private TextView mTvTestZoom;
private Button mBtUp, mBtDown;
// Model
private int mCurrentScale = 1;
// OnClick listener
private View.OnClickListener mOnClickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.bt_up : {
upScale();
setText();
} break;
case R.id.bt_down : {
downScale();
setText();
} break;
}
}
};
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_text_scale);
initView();
initEvent();
}
private void initView() {
mTvTestZoom = (TextView) findViewById(R.id.tv_test_scale);
mBtUp = (Button) findViewById(R.id.bt_up);
mBtDown = (Button) findViewById(R.id.bt_down);
}
private void initEvent() {
mBtDown.setOnClickListener(mOnClickListener);
mBtUp.setOnClickListener(mOnClickListener);
}
private void upScale() {
mCurrentScale += 1;
mTvTestZoom.animate().setDuration(0).scaleX(mCurrentScale).scaleY(mCurrentScale).start();
}
private void downScale() {
mCurrentScale -= 1;
mTvTestZoom.animate().setDuration(0).scaleX(mCurrentScale).scaleY(mCurrentScale).start();
}
private void setText() {
mTvTestZoom.setText(mCurrentScale + "");
}
}

This may happen because the textview exceeds the layout bounds of its parent. To overcome this, simple put android:clipChildren="false" in the xml description of the immediate parent of the textview. You may also need to do it for their parents too.
EDIT:
Upon testing the code myself, I found that the textview did disappear with following log message:
E/OpenGLRenderer: Font size too large to fit in cache. width, height = 635, 1028
This is due to a possible issue in the Android Hardware acceleration modules. One of the ways to avoid this is:
mTvTestZoom.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
This works well and the textView does not disappear after a certain size but, since it disables hardware acceleration for the specific textview, it may lose antialiasing.

Related

Changing an image on a button click

iam new to android development and here iam trying to change images on a button click ,iam using the animate() method to fade one of the images and achieve the result .The first button click is fading the images but the second time i click on this button ,it doesnt give any result (images doesnt fade ) .
give me any possible solutions.thankyou
.java file
package e.nani.bestimage;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
public void change(View view) {
int flag=0;
ImageView img1 = (ImageView) findViewById(R.id.single);
ImageView img2 = (ImageView) findViewById(R.id.withands);
switch(flag){
case 0:img1.animate().alpha(0f).setDuration(2000);
img2.animate().alpha(1f).setDuration(2000);
flag=1;
break;
case 1: img1.animate().alpha(1f).setDuration(2000);
img2.animate().alpha(0f).setDuration(2000);
flag=0;
break;
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView img1=(ImageView) findViewById(R.id.single);
ImageView img2=(ImageView) findViewById(R.id.withands);
img1.animate().alpha(1f).setDuration(2000);
img2.animate().alpha(0f).setDuration(2);
}
}
xml file
<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_purple"
tools:context=".MainActivity">
<ImageButton
android:id="#+id/single"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
app:srcCompat="#drawable/imgthree" />
<ImageView
android:id="#+id/withands"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
app:srcCompat="#drawable/imgsix" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="98dp"
android:alpha="0.7"
android:background="#android:color/background_dark"
android:onClick="change"
android:text="find out the person"
android:textColor="#android:color/holo_blue_bright" />
</android.widget.RelativeLayout>
Anytime the change() method is called it's setting the flag equals to 0. Try this :
public class MainActivity extends AppCompatActivity {
int flag;
public void change(View view) {
ImageView img1 = (ImageView) findViewById(R.id.single);
ImageView img2 = (ImageView) findViewById(R.id.withands);
switch(flag){
case 0:
img1.animate().alpha(0f).setDuration(2000);
img2.animate().alpha(1f).setDuration(2000);
flag=1;
break;
case 1:
img1.animate().alpha(1f).setDuration(2000);
img2.animate().alpha(0f).setDuration(2000);
flag=0;
break;
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
flag = 0;
ImageView img1=(ImageView) findViewById(R.id.single);
ImageView img2=(ImageView) findViewById(R.id.withands);
img1.animate().alpha(1f).setDuration(2000);
img2.animate().alpha(0f).setDuration(2);
}
}

Java Android Change Position of an ImageView dynamically

I am new in program Java/Android and got a small problem.
I searched why my code doesn't work but I didn't find an answer - so here is my Problem:
I want to change the position of an ImageView at runtime by a Button. I have two buttons - left and right. But the curious thing is - only one is working (the button for moving right). If I click the button for moving left nothing changed.
I hope someone can help me because I searched a long time for this detail.
Tanks a lot for any help!
Here is the Code:
package de.androidnewcomer.bildattribute;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button leftButton=(Button)findViewById(R.id.buttonLeft);
leftButton.setOnClickListener(this);
Button rightButton=(Button)findViewById(R.id.buttonRight);
rightButton.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.buttonLeft:
moveLeft();
case R.id.buttonRight:
moveRight();
}
}
private void moveLeft() {
ImageView ball=(ImageView)findViewById(R.id.ball);
FrameLayout.LayoutParams paramsLeft=(FrameLayout.LayoutParams)ball.getLayoutParams();
paramsLeft.width=50;
paramsLeft.height=50;
paramsLeft.rightMargin +=20;
ball.setLayoutParams(paramsLeft);
}
private void moveRight() {
ImageView ball=(ImageView)findViewById(R.id.ball);
FrameLayout.LayoutParams paramsRight=(FrameLayout.LayoutParams) ball.getLayoutParams();
paramsRight.width=50;
paramsRight.height=50;
paramsRight.leftMargin +=20;
ball.setLayoutParams(paramsRight);
}
}
And the XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="de.androidnewcomer.bildattribute.MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/layout1">
<Button
android:text="Left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonLeft"
android:layout_gravity="bottom|left"
android:layout_marginLeft="50dp" />
<Button
android:text="Right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonRight"
android:layout_gravity="bottom|right"
tools:layout_marginRight="50dp" />
<ImageView
app:srcCompat="#drawable/image1"
android:id="#+id/image1"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_height="20dp"
android:layout_width="20dp" />
</FrameLayout>
The problem is in your onClick() - The break; statements are missing:
#Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.buttonLeft:
moveLeft();
break; // MISSING
case R.id.buttonRight:
moveRight();
break; // MISSING
}
}
Without the break statement , when you hit buttonLeft, you perform both moveLeft() & moveRight() both , which result in no change in the layout.
Even though you need to modify you onClick method as it has been said, your moveLeft method should update the left margin (just as moveRight)
private void moveLeft() {
ImageView ball=(ImageView)findViewById(R.id.ball);
FrameLayout.LayoutParams paramsLeft=(FrameLayout.LayoutParams)ball.getLayoutParams();
paramsLeft.width=50;
paramsLeft.height=50;
paramsLeft.leftMargin -=20;
ball.setLayoutParams(paramsLeft);
}
You can experiment on your layout and see what happens if you add both left and right margin to an element, surely it is not what you expect.

I want to hide and unhide text using a button in android ; The code is correct but it still doesn't work

Here is the xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_hide"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.andrew.hide.Hide">
<TextView
android:text="This is the text"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="81dp"
android:id="#+id/textView"
android:textSize="40sp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:text="Hide"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/button"
android:textSize="28sp"
android:onClick="hide"
android:layout_marginBottom="184dp" />
</RelativeLayout>
Here is the java file
package com.example.andrew.hide;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Hide extends Activity {
Button b1;
TextView t1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hide);
b1=(Button) findViewById(R.id.button);
t1=(TextView) findViewById(R.id.textView);
String text=b1.getText().toString();
}
public void hide(View view) {
if (b1.getText().toString() == "Hide") {
t1.setVisibility(View.INVISIBLE);
b1.setText("Unhide");
}
if (b1.getText().toString() == "Unhide") {
t1.setVisibility(View.VISIBLE);
b1.setText("Hide");
}
}
}
I am new to android development , so ignore if this doubt is silly.
I manually checked by using Log and I found that getText works perfectly
Nothing happens whenever i click the button (b1 here),How do I fix this?
Use equals to compare strings.
Try this,
public void hide(View view) {
String text = b1.getText().toString();
if (text.equals("Hide")) {
t1.setVisibility(View.INVISIBLE);
b1.setText("Unhide");
} else if (text.equals("Unhide")) {
t1.setVisibility(View.VISIBLE);
b1.setText("Hide");
}
}
Why don't you simply check the TextView visibility and perform your actions based on that ? It's all the setters and getters right ?
b1.onClickListener(new OnClickListener() {
if (t1.getVisibility() == View.Visible) {
t1.setVisibilty(View.GONE);
//--- your code
} else {
t1.setVisibilty(View.VISIBLE);
//--- your code
}
);

App starts normally But crashes when I click Button "oneplus"

First of all let me tell you that I am a beginner at this... I started to try developing apps about a week ago.
When I start my app on a real device it starts normally But when I click the button "oneplus" it says that app isn't responding...
this app adds one number to the number in TextView .Earlier I faced same problem and thought it was because of fragments.So i removed them and made a very simple app But still the problem persists
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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="80dp"
android:text="0"
android:id="#+id/num"
android:textSize="70sp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="100dp"
android:text=" + 1 "
android:textSize="50sp"
android:id="#+id/plusone"
android:onClick="onClick"
/>
</RelativeLayout>`
mainactivity.java
package com.example.tjain.oneup;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements View.OnClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public void onClick(View v) {
final TextView number = (TextView) findViewById(R.id.num);
int original = Integer.parseInt(number.getText().toString());
int newnum = original + 1;
number.setText(newnum);
}
}
I am facing this error in other apps too. Maybe I am repeating my mistake . Please point it out. Thanks in advance
As I doubt for two scenario in your onClick for Exception
NumberFormat Exception
ResourceNotFound Exception
For First,
try
{
int original = Integer.parseInt(number.getText().toString());
}catch(Exception ex)
{
ex.printStacktrace();
}
For Second,
Because int is not a argument for TextView's setText (only if its not a part of String resource id), as it will find with resource id not accepting as String value. and obvious Resource Not Found exception
you have to convert int to String,
number.setText(String.valueOf(newnum));
What I would recommend doing is adding your UI elements at the class level of your activity so you have one TextView object and one Button object, that way you only have to search for the resource once and you can add a click listener to the button itself like this:
public class MainActivity extends Activity{
private TextView mNumberTextView;
private Button mOnePlusButton;
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNumberTextView = findViewbyId(R.id.num);
mOnePlusButton = findViewbyId(R.id.plusone);
mOnePlusButton.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
int original = Integer.parseInt(mNumberTextView.getText().toString());
mNumberTextView.setText(original + 1);
}
});
}
}
Edit: Since you're still new at this, it's always a good idea to check the documentation.
You should use
number.setText(+newnum);
instead
number.setText(newnum);

Android App Multiple Views

This is one of the noobiest questions you will ever find, but in my Android app, I need to have a few different "screens"; one where you log in, and a view that represents a question (there will be multiple questions, so I need to make a view for each question and have it change to the next view when a next button is clicked. Let me explain with a flow chart:
User Opens App -> Login Screen -> User Logs In -> View changes to auto generated view for question 1 -> Next button clicked -> question 2 -> does all questions -> Final view that says you are done.
I have created two xml layout files, one called main and one called quiz (which represents a question).
I will elaborate on anything needed.
UPDATE
Here are my two activity classes:
package me.nrubin29.quiz.student;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Main extends Activity {
/**
* Called when the activity is first created.
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button done = (Button) findViewById(R.id.done);
final EditText serverAddress = (EditText) findViewById(R.id.serverAddress);
final EditText secretNumber = (EditText) findViewById(R.id.secretNumber);
final EditText name = (EditText) findViewById(R.id.name);
done.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String addr = serverAddress.getText().toString();
String num = secretNumber.getText().toString();
String n = name.getText().toString();
if (addr.equals("") || num.equals("") || n.equals("")) {
Toast.makeText(getApplicationContext(), "You didn't fill in all the fields.", Toast.LENGTH_LONG).show();
return;
}
new Connection().initConnection(Main.this, addr, num, n);
}
});
}
}
package me.nrubin29.quiz.student;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioButton;
public class Quiz extends Activity {
/**
* Called when the activity is first created.
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.quiz);
final RadioButton radioButton1 = (RadioButton) findViewById(R.id.radioButton);
final RadioButton radioButton2 = (RadioButton) findViewById(R.id.radioButton1);
final RadioButton radioButton3 = (RadioButton) findViewById(R.id.radioButton2);
final RadioButton radioButton4 = (RadioButton) findViewById(R.id.radioButton3);
radioButton1.setText("Testing!");
}
}
And here are my two XMLs:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Please enter the server address and secret number your teacher gives you."
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/serverAddress" android:layout_gravity="center"
android:phoneNumber="true"
android:hint="Server Address"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/secretNumber" android:layout_gravity="center"
android:phoneNumber="true"
android:hint="Secret Number"/>
<Space
android:layout_width="fill_parent"
android:layout_height="20px"
android:id="#+id/space1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please enter your name."
android:id="#+id/textView2" android:layout_gravity="left|center_vertical"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/name" android:layout_gravity="left|center_vertical"
android:hint="Name"/>
<Space
android:layout_width="fill_parent"
android:layout_height="20px"
android:id="#+id/space"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Done"
android:id="#+id/done" android:layout_gravity="center"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Question"
android:id="#+id/textView"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
android:id="#+id/radioButton"
android:layout_gravity="center"/>
<RadioButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New RadioButton"
android:id="#+id/radioButton1"/>
<RadioButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New RadioButton"
android:id="#+id/radioButton2"/>
<RadioButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New RadioButton"
android:id="#+id/radioButton3"/>
</RadioGroup>
</LinearLayout>
UPDATE! And here's my newer Connection class:
package me.nrubin29.quiz.student;
import android.app.Activity;
import android.content.Intent;
import android.widget.Toast;
import me.nrubin29.quiz.student.receivedQuiz.Quiz;
import java.io.EOFException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
public class Connection {
private Connection() { }
private static Connection instance = new Connection();
public static Connection getInstance() {
return instance;
}
private Quiz quiz;
private Socket socket;
private Thread reader;
private ObjectInputStream inputStream;
private ObjectOutputStream outputStream;
public void initConnection(final Activity activity, final String ip, final String port, final String name) {
new Thread(new Runnable() {
public void run() {
try {
activity.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(activity.getApplicationContext(), "Starting connection to " + ip + ":" + Integer.parseInt(port), Toast.LENGTH_SHORT).show();
}
});
socket = new Socket(ip, Integer.parseInt(port));
activity.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(activity.getApplicationContext(), "Connected!", Toast.LENGTH_SHORT).show();
}
});
outputStream = new ObjectOutputStream(socket.getOutputStream());
inputStream = new ObjectInputStream(socket.getInputStream());
outputStream.writeObject(name);
quiz = new Quiz((String) inputStream.readObject());
Intent i = new Intent(activity, me.nrubin29.quiz.student.Quiz.class);
activity.startActivity(i);
reader = new Thread(new Runnable() {
public void run() {
while (true) {
try {
Object in = inputStream.readObject();
}
catch (final EOFException e) { activity.runOnUiThread(new Runnable() { public void run() { Toast.makeText(activity.getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } }); }
catch (Exception e) { e.printStackTrace(); }
}
}
});
reader.start();
}
catch (Exception e) { e.printStackTrace(); }
}
}).start();
}
public Quiz getQuiz() {
return this.quiz;
}
}
As far as the Activity for Quiz, I guess I should make a constructor that takes the question and answers and sets the text of the radio buttons? Also, how exactly (code example would rock) would I create go about answering the question with the code above?
For the login Activity just use whatever you layout you want with the Views needed (Spinner, TextView, Button, etc...).
If the question screens will all be the same then you can just use Fragments coupled with ViewPager if you want. This should work nicely for your needs. This will allow you to supply new data for each question but easily keep the same layout.
VeiwPager Docs
ViewPager example I haven't looked at it much but his tutorials are usually pretty good.
If ViewPager is more than you need/want right now, you can simply have one View for the question such as a TextView and change the text when the Button is clicked.
Edit
Change your Intent to use that Context
Intent i = new Intent(activity, Quiz.class);
activity.startActivity(i);
You can implement this by having two different Activities and each having different content views (XML Files).
The default Launcher activity will be your Login Screen with the login layout file.
The second activity should be having a view to handle questions. This can be done using your apt view groups like RelativeLAyout, LinearLayout, FrameLayout and so on. There are numberous examples on each in the internet. Just do a search for tutorials on each.
Final view (you are done) can be implemented in the same activity with a different view or just with a AlertDialog.

Categories