EDIT: updated my code , posted more of the code for you to see .
EDIT: why am i being downvoted ?
EDIT2: broke my code lol , im going to reverse all you're suggestions , and try the xml option provided
i would like to know if i can use startActivityForResult in my main activity.
i'm opening a scannerview with the code below ,
what i see as my SECOND activiy .
how could i get that result because it's not officially another activity it's only a method.
Button sendButton;
//EditText edt4;
EditText edt2;
#SuppressLint("CutPasteId")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edt4 = findViewById(R.id.editText4);
ZXingScannerView mScannerView = findViewById(xmlScannerView););
#Override
public void onResume() {
super.onResume();
mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
mScannerView.startCamera(); // Start camera on resume
}
#Override
public void onPause() {
super.onPause();
mScannerView.stopCamera(); // Stop camera on pause
}
public void onClick(View v){
ZXingScannerView mScannerView = new ZXingScannerView(this);
mScannerView.setVisibility(View.VISIBLE);
mScannerView.setResultHandler(this);
mScannerView.startCamera();
}
//EditText editText4;
EditText edt4;
#Override
public void handleResult(final Result result) {
//handle result
Log.v("handleResult", result.getText());
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Ordernummer of Locatie");
builder.setMessage(result.getText());
AlertDialog alertDialog = builder.create();
alertDialog.show();
//edt4.setText(result.getText());
//edt4 = findViewById(editText4);
//edt4.setText(String.valueOf(result.getText()));
runOnUiThread(new Runnable() {
#Override
public void run() {
updateScannerData(1,result.getText());
}
});
}
private void updateScannerData(int scanType, String scannedCode){
//startActivity(new Intent(this,MainActivity.class));
//this.finish();
edt4.setText(scannedCode);
}
#Override
public void onBackPressed()
{
startActivity(new Intent(this,MainActivity.class));
this.finish();
}
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/relLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:background="#mipmap/ic_launcher_foreground">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<EditText
android:id="#+id/editText4"
android:layout_width="match_parent"
android:layout_height="62dp"
android:layout_marginTop="67dp"
android:ems="10"
android:hint="#string/scan_locatie"
android:inputType="text"
android:text=""
tools:backgroundTint="#android:color/holo_red_light" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editText4"
android:layout_centerHorizontal="true"
android:background="#android:color/holo_red_light"
android:onClick="onClick"
android:text="#string/scan_qr"
tools:text="scan qr code" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="61dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="197dp"
android:ems="10"
android:hint="#string/scan_order"
android:inputType=""
android:visibility="visible"
tools:backgroundTint="#android:color/holo_red_light" />
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editText2"
android:layout_centerHorizontal="true"
android:background="#android:color/holo_red_light"
android:onClick="onClick"
android:text="#string/scan_qr"
tools:text="scan qr code" />
<Button
android:id="#+id/sendButton"
android:layout_width="157dp"
android:layout_height="32dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="72dp"
android:background="#android:color/holo_red_light"
android:text="#string/button"
tools:text="Versturen.." />
<Button
android:id="#+id/button3"
android:layout_width="40dp"
android:layout_height="38dp"
android:layout_alignBaseline="#+id/editText2"
android:layout_alignParentEnd="true"
android:background="#android:drawable/ic_delete" />
<Button
android:id="#+id/button4"
android:layout_width="39dp"
android:layout_height="37dp"
android:layout_alignBaseline="#+id/editText4"
android:layout_alignParentEnd="true"
android:background="#android:drawable/ic_delete" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<me.dm7.barcodescanner.zxing.ZXingScannerView
android:id="#+id/xmlScannerView"
android:visibility="gone"
android:layout_height="match_parent"
android:layout_width="match_parent" />
</FrameLayout>
No you can't, either use multiple layout groups in your activity's layout or use multiple fragments.
if you go for the first option, you should add the ZXingScannerView in you XML layout and simple tangle it's visibility if you want to use it
<me.dm7.barcodescanner.zxing.ZXingScannerView
android:width="match_parent"
height="match_parent"
android:id="someId"
android:visibility="gone"
/>
And then in your code
private ZXingScannerView mScannerView;
#Override
public void onCreate(Bundle state) {
super.onCreate(state);
setContentView(someLayout);
mScannerView = findViewById(SomeId);
mScannerView.setFormats(ZXingScannerView.ALL_FORMATS);// dont forget this
mScannerView.setResultHandler(this);
mScannerView.startCamera()
}
public void onClick(View v){
mScannerView.setVisibility(View.Visible);
}
EDIT
Call setFormats see above and start the camera is the onCreate() and change the visibility in the XML to INVISIBLE
EDIT 2
Your XML is supposed to be like this
<FrameLayout 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"
tools:background="#mipmap/ic_launcher_foreground">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<me.dm7.barcodescanner.zxing.ZXingScannerView
android:id="#+id/xmlScannerView"
android:visibility="gone"
android:layout_height="match_parent"
android:layout_width="match_parent" />
<RelativeLayout
android:id="#+id/someId"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/editText4"
android:layout_width="match_parent"
android:layout_height="62dp"
android:layout_marginTop="67dp"
android:ems="10"
android:hint="#string/scan_locatie"
android:inputType="text"
android:text=""
tools:backgroundTint="#android:color/holo_red_light" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editText4"
android:layout_centerHorizontal="true"
android:background="#android:color/holo_red_light"
android:onClick="onClick"
android:text="#string/scan_qr"
tools:text="scan qr code" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="61dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="197dp"
android:ems="10"
android:hint="#string/scan_order"
android:inputType=""
android:visibility="visible"
tools:backgroundTint="#android:color/holo_red_light" />
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editText2"
android:layout_centerHorizontal="true"
android:background="#android:color/holo_red_light"
android:onClick="onClick"
android:text="#string/scan_qr"
tools:text="scan qr code" />
<Button
android:id="#+id/sendButton"
android:layout_width="157dp"
android:layout_height="32dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="72dp"
android:background="#android:color/holo_red_light"
android:text="#string/button"
tools:text="Versturen.." />
<Button
android:id="#+id/button3"
android:layout_width="40dp"
android:layout_height="38dp"
android:layout_alignBaseline="#+id/editText2"
android:layout_alignParentEnd="true"
android:background="#android:drawable/ic_delete" />
<Button
android:id="#+id/button4"
android:layout_width="39dp"
android:layout_height="37dp"
android:layout_alignBaseline="#+id/editText4"
android:layout_alignParentEnd="true"
android:background="#android:drawable/ic_delete" />
</RelativeLayout>
</FrameLayout>
And then when calling the onClick
public void onClick(View v){
yourRelativeLayout.setVisibility(View.Invisible);
mScannerView.setVisibility(View.Visible);
}
Well, I think we need to take a look at your current code and the ZXingScannerView. If we take a look at the Github repository of the ZXingScannerView, there is an example which differs a bit from your implementation.
First of all, you should call setContentView(mScannerView);, only in your Activity's onCreate() once. Right now, when you click, the entire view gets redrawn, which is not needed. You also set the resultHandler each time when you click on the button, which might cause problems as well.
This code is taken from the Github repo of the element you are using, so please make your Activity look like this.
https://github.com/dm77/barcodescanner
public class SimpleScannerActivity extends Activity implements ZBarScannerView.ResultHandler {
private ZBarScannerView mScannerView;
#Override
public void onCreate(Bundle state) {
super.onCreate(state);
mScannerView = new ZBarScannerView(this); // Programmatically initialize the scanner view
setContentView(mScannerView); // Set the scanner view as the content view
}
#Override
public void onResume() {
super.onResume();
mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
mScannerView.startCamera(); // Start camera on resume
}
#Override
public void onPause() {
super.onPause();
mScannerView.stopCamera(); // Stop camera on pause
}
#Override
public void handleResult(Result rawResult) {
// Do something with the result here
Log.v(TAG, rawResult.getContents()); // Prints scan results
Log.v(TAG, rawResult.getBarcodeFormat().getName()); // Prints the scan format (qrcode, pdf417 etc.)
// If you would like to resume scanning, call this method below:
mScannerView.resumeCameraPreview(this);
}
}
Also note that you will need permissions to access the phone's camera.
Related
I am currently creating an app on Android Studio.
I use different buttons (in the same activity) that go to different activities. The problem is that, with one button, it all works, but when I add another one the emulator crashes.
Here is my code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
defineButtons();
}
public void defineButtons() {
findViewById(R.id.next1).setOnClickListener(buttonClickListener);
findViewById(R.id.next2).setOnClickListener(buttonClickListener);
findViewById(R.id.next3).setOnClickListener(buttonClickListener);
}
private View.OnClickListener buttonClickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.next1:
Intent Next1 = new Intent (Start.this, Next1.class);
startActivity(Next1);
break;
case R.id.next2:
Intent Next2 = new Intent (Start.this, Next2.class);
startActivity(Next2);
break;
case R.id.next3:
Intent Next3 = new Intent (Start.this, Next3.class);
startActivity(Next3);
break;
}
}
};
And here the XML:
<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"
tools:context=".Start"
android:background="#drawable/background">
<TextView
android:layout_width="match_parent"
android:layout_height="700px"
android:id="#+id/statement"
android:text="TEXT1"
android:background="#drawable/button_border"
android:textColor="#000000"
android:alpha="0.95"
android:layout_marginHorizontal="70px"
android:layout_marginTop="180px"
android:gravity="center"
android:paddingHorizontal="50px"
android:textSize="16sp"
/>
<Button
android:id="#+id/next1"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="150px"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="160dp"
android:layout_marginHorizontal="70px"
android:alpha="0.9"
android:background="#drawable/button_border"
android:text="TEXT2"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textAllCaps="false"/>
<Button
android:id="#+id/next2"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="150px"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="90dp"
android:layout_marginHorizontal="70px"
android:alpha="0.9"
android:background="#drawable/button_border"
android:text="TEXT3"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textAllCaps="false"/>
<Button
android:id="#+id/next3"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="150px"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:layout_marginHorizontal="70px"
android:alpha="0.9"
android:background="#drawable/button_border"
android:text="TEXT4"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textAllCaps="false"/>
</RelativeLayout>
I know this is messy, I'm new at programming.
Your code is perfectly fine you just need to declare your Next2, and Next3 activities in manifest file like this
<activity android:name=".Next2"
android:screenOrientation="portrait"/>
<activity android:name=".Next3"
android:screenOrientation="portrait"/>
Android reads your app components from manifest file, refer this link for more details https://developer.android.com/guide/topics/manifest/manifest-intro
my current Zxing scanner screen looks like this,
I want to add a textview and couple of buttons on it, I had tried many procedures but nothing worked can anyone guide me, I will be humbly looking forward for your kind help
here's the Code
Java file:
private ZXingScannerView mScannerView;
#Override
public void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.activity_qrresult);
mScannerView = new ZXingScannerView(this);
setContentView(mScannerView);
}
#Override
public void onResume() {
super.onResume();
mScannerView.setResultHandler(this);
mScannerView.startCamera();
Toast.makeText(getApplicationContext(),"Scan QR code to Send
Money",Toast.LENGTH_LONG).show();
}
#Override
public void onPause() {
super.onPause();
mScannerView.stopCamera(); // Stop camera on pause
}
#Override
public void handleResult(Result rawResult) {
// Do something with the result here
if(rawResult.getText().toString().equals("Test Ewallet Test")){
Toast.makeText(getApplicationContext(), rawResult.getText(),
Toast.LENGTH_SHORT).show();
Intent go = new Intent(qrresult.this,sendmoney.class);
startActivity(go);
}else {
Toast.makeText(getApplicationContext(), "Couldn't scan the
QRcode, Please Try again ", Toast.LENGTH_SHORT).show();
mScannerView.resumeCameraPreview(this);
}
// mScannerView.resumeCameraPreview(this);
// If you would like to resume scanning, call this method below:
//mScannerView.resumeCameraPreview(this);
}
}
heres xml file
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.tajveezrehman.applicationtest.yourqr">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
android:id="#+id/flashlight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:text="Button" />
<Button
android:id="#+id/open image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:text="Button" />
<TextView
android:id="#+id/camtxt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_weight="0.8"
android:text="#string/scanner"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
</RelativeLayout>
use RelativeLayout for it like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<me.dm7.barcodescanner.zxing.ZXingScannerView
android:id="#+id/zxscan"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<ImageView
android:id="#+id/btn_flash"
android:layout_marginBottom="15dp"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:src="#drawable/flash_100"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
its look like :
I would like to ask on how to achieve to wrap a content in alertdialog?
Because the current output of my dialog has an excess white field.
Hope someone can help me to understand this problem thanks.
Here is my activity_dialog.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:minWidth="10dp"
android:minHeight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context="com.bloxofcode.toggle.MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="50sp"
android:background="#color/colorHeaderDialog"
android:textColor="#android:color/white"
android:text="#string/select_gender"
android:padding="15dp"
android:gravity="center_horizontal|left"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:padding="15dp"
android:text="Sample"
android:id="#+id/editText" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ToggleButton
android:text="ToggleButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/toggleButtonMale"
android:textOn=""
android:textOff=""
android:focusable="false"
android:background="#drawable/check_male"
android:layout_weight="1" />
<ToggleButton
android:text="ToggleButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/toggleButtonFemale"
android:textOn=""
android:textOff=""
android:focusable="false"
android:background="#drawable/check_male"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<Button
android:id="#+id/btnCancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Cancel"
android:textSize="20dp"
android:padding="30dp"
android:textColor="#android:color/white"
android:layout_weight="1"/>
<Button
android:id="#+id/btnAccept"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Accept"
android:textSize="20dp"
android:padding="30dp"
android:background="#color/colorDialogOK"
android:textColor="#android:color/white"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Here is some of my implementation in the MainActivity.java:
AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this);
View mView = getLayoutInflater().inflate(R.layout.activity_dialog, null);
.....
mBuilder.setView(mView);
final AlertDialog dialog = mBuilder.create();
dialog.show();
Try Creating a dialog like this. this works perfect and then right away your dialog logic is seperated from you activity logic
public class CustomDialog extends Dialog implements
android.view.View.OnClickListener {
public Activity c;
public CustomDialog d;
public Button yes, no;
public CustomDialog(Activity a) {
super(a);
// TODO Auto-generated constructor stub
this.c = a;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog_layout);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//dosomething
}
});
}
}
Hope it is not correct to wrap the content of dialog as it might disrupt the view in tablets and larger devices.
Anyhow, basing upon your requirement.. hope this link works
AlertDialog with custom view: Resize to wrap the view's content
I am testing an app that I am in the process of making. When the application starts up, the splash screen is supposed to do a fade in/fade out animation into the login screen. When the application starts up FOR THE FIRST TIME, the animation works fine. But once I clear the application from task manager and restart it, the animation doesn't appear and it goes straight to the login screen with no animation occuring. Attached are the parts of the code dealing with the animation. If any other piece of the code is needed I will provide that as well. I just want it so the animation runs EVERY TIME the application runs.
SplashScreen.java
public class SplashScreen extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timerThread = new Thread(){
public void run(){
try{
sleep(3000);
}catch(InterruptedException e){
e.printStackTrace();
}
finally{
Intent intent = new Intent(SplashScreen.this,LoginActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
}
};
timerThread.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
LoginActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
// Set up the login form.
registerButton = (Button)findViewById(R.id.button);
registerButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(LoginActivity.this,Register.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_left_in, R.anim.slide_left_out);
}
});
fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="2000" />
fade_out.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0"
android:fillAfter="true"
android:duration="2000" />
activity_login.xml
<LinearLayout 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:gravity="center_horizontal"
android:orientation="vertical"
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.drinkuprewards.julian.drinkuprewards.LoginActivity"
android:background="#97007C">
<!-- Login progress -->
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ScrollView
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="false">
</ScrollView>
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/imageView"
android:src="#drawable/logosm"
android:contentDescription="#string/mainlogo" />
<EditText
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_email"
android:maxLines="1"
android:singleLine="true"
android:autoText="false"
android:background="#fef500"
android:textColor="#000000"
android:inputType="textEmailAddress" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/spacer" />
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true"
android:autoText="false"
android:background="#fef500"
android:textColor="#000000" />
<Button
android:id="#+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/action_register"
android:textStyle="bold"
android:layout_gravity="center_horizontal"
android:background="#fef500"
android:textColor="#000000" />
<Button
style="?android:textAppearanceSmall"
android:id="#+id/button"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/action_sign_in"
android:textStyle="bold"
android:layout_gravity="center_horizontal"
android:background="#fef500"
android:onClick="Register"
android:textColor="#000000" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/version_number"
android:id="#+id/textView"
android:textColor="#000000" />
</LinearLayout>
do not use sleep() to delay starting another activity. You can do what you want like
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(SplashScreen.this,LoginActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
finish();
}
}, 3000);
this should work.
Sorry guys, But I am new, This is my homepage java class.
IntroButton is Working well, but Feedback is not working, i am
touching feedback button, but it is untouched. mean no output.
Created by AwaisButt awais.b7solpk#gmail.com on 4/15/2015.
public class HomePage extends Activity { protected void
onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.homepage);
Button introButton = (Button) findViewById(R.id.bIntro);
Button feedBackButton = (Button) findViewById(R.id.bFeedBack);
introButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(HomePage.this,Introduction.class);
startActivity(intent);
}
});
feedBackButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(HomePage.this,FeedBack.class);
startActivity(intent);
}
});
}
XML File
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/homepage">
<Button
android:layout_width="139dp"
android:layout_height="44dp"
android:id="#+id/bIntro"
android:layout_marginLeft="23dp"
android:layout_marginTop="180dp"
android:background="#android:color/transparent"
android:layout_gravity="center_vertical" />
<Button
android:layout_width="139dp"
android:background="#android:color/transparent"
android:layout_height="44dp"
android:text="FeedBack"
android:id="#+id/bFeedBack"
android:layout_marginLeft="23dp"
android:visibility="invisible"
android:layout_marginTop="1dp"
android:layout_gravity="center_vertical" />
<Button
android:layout_width="139dp"
android:background="#android:color/transparent"
android:layout_height="44dp"
android:visibility="invisible"
android:text="Order"
android:id="#+id/bOrder"
android:layout_marginLeft="23dp"
android:layout_marginTop="-4dp"
android:layout_gravity="center_vertical" />
<Button
android:layout_width="139dp"
android:visibility="invisible"
android:layout_height="44dp"
android:text="Catalogue"
android:background="#android:color/transparent"
android:id="#+id/bCatalogue"
android:layout_marginLeft="23dp"
android:layout_marginTop="-7dp"
android:layout_gravity="center_vertical" />
<Button
android:layout_width="139dp"
android:visibility="invisible"
android:layout_height="44dp"
android:text="Web"
android:id="#+id/bWeb"
android:layout_marginLeft="23dp"
android:layout_marginTop="-10dp"
android:background="#android:color/transparent"
android:layout_gravity="center_vertical" /> </LinearLayout>
Mistake:
You did a mistake, visibility of the feedback button is Invisible! Intro button is getting clicked because it's visible in your layout!
FYI
View.GONE This view is invisible, and it doesn't take any space for
layout purposes.
View.INVISIBLE This view is invisible, but it still takes up space for
layout purposes.
Check your OnClickListener() is of type View.OnClickListener().
It's because you set that button as Invisible.
<Button
android:layout_width="139dp"
android:background="#android:color/transparent"
android:layout_height="44dp"
android:text="FeedBack"
android:id="#+id/bFeedBack"
android:layout_marginLeft="23dp"
android:visibility="invisible" // here
android:layout_marginTop="1dp"
android:layout_gravity="center_vertical" />
remove that line. It will work.
One more solution is,
you can use this line in onCreate method after you find the button id.
feedBackButton.setVisibility(View.VISIBLE);
Good luck!