lundi 2 février 2015

How to solve requestFeature() must be called before adding content in android

I am creating an application that consists of the simple and small registration form pop up in an alert dialog when we click a button. But it was showing an error called android.util.AndroidRuntimeException: requestFeature() must be called before adding content please make it solve


Here i also used the SQLite databse This is my activity



package com.example.androidmaterial;

import com.gc.materialdesign.views.ButtonFlat;
import com.gc.materialdesign.views.ButtonFloat;
import com.gc.materialdesign.views.ButtonRectangle;
import com.gc.materialdesign.widgets.Dialog;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Sample extends Activity
{
ButtonFloat keyboard;
ButtonRectangle hide_keyboard;
LoginDataBaseAdapter login_database_adapter;
ButtonFlat database;
EditText name;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_sample);
login_database_adapter = new LoginDataBaseAdapter(Sample.this);
login_database_adapter = login_database_adapter.open();

database = (ButtonFlat)findViewById(R.id.buttonflat);
database.setOnClickListener(new View.OnClickListener()
{

@Override
public void onClick(View v)
{
Dialog dialog_signup = new Dialog(Sample.this,"Registration","Please Fill all the details");
dialog_signup.setContentView(R.layout.activity_signup);
final EditText username = (EditText)dialog_signup.findViewById(R.id.editText1);
final EditText password = (EditText)dialog_signup.findViewById(R.id.editText2);
final EditText confirmpass = (EditText)dialog_signup.findViewById(R.id.editText3);
final EditText name = (EditText)dialog_signup.findViewById(R.id.editText4);
final ButtonFlat register = (ButtonFlat)dialog_signup.findViewById(R.id.buttonflat);
register.setOnClickListener(new View.OnClickListener()
{

@Override
public void onClick(View v)
{
String user_name = name.getText().toString();
String mqs_user_name = username.getText().toString();
String mqs_password = password.getText().toString();
String mqs_confirmpass = confirmpass.getText().toString();

if(mqs_user_name.equals("")||mqs_password.equals("")||mqs_confirmpass.equals(""))
{
Toast.makeText(Sample.this, "Some fields are empty please enter all the fields",Toast.LENGTH_LONG).show();
}
if(mqs_password!=mqs_confirmpass)
{
Toast.makeText(Sample.this, "Passwords did not match",Toast.LENGTH_LONG).show();
}
else
{

login_database_adapter.insertEntry(mqs_user_name, mqs_password);
Toast.makeText(Sample.this, "Account Successfully created"+" "+user_name,Toast.LENGTH_LONG).show();
}


}
});
dialog_signup.show();

}
});


keyboard = (ButtonFloat)findViewById(R.id.buttonFloat);
hide_keyboard = (ButtonRectangle)findViewById(R.id.button_2);
hide_keyboard.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v)
{try{
InputMethodManager imm_2 = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm_2.hideSoftInputFromInputMethod(getCurrentFocus().getWindowToken(),0);
}
catch(Exception e)
{
Toast.makeText(Sample.this, e.getMessage(), Toast.LENGTH_LONG).show();
}

}
});
keyboard.requestFocus();
keyboard.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Dialog dialog = new Dialog(Sample.this, "MedeQuip", "Hello...This is a sample dialog box check");
dialog.setOnAcceptButtonClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Toast.makeText(Sample.this, "Click accept button", 1).show();
}
});
dialog.setOnCancelButtonClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Toast.makeText(Sample.this, "Click cancel button", 1).show();
}
});
dialog.show();
}
});

}
@Override
protected void onDestroy() {


login_database_adapter.close();
super.onDestroy();
}
}

Aucun commentaire:

Enregistrer un commentaire