I'm new to android studio.
I've imported project in android studio and without any changes I'm getting the error.
'Class or interface Expected'
Can anyone help me out?
class this.cls0
implements android.view.istener
{
final LyricsEdit this$0;
public void onClick(View view)
{
mDismissMethod = 1;
mLyrics = mEditLyrics.getText().toString();
dismiss();
}
()
{
this$0 = LyricsEdit.this;
super();
}
}
If you would like to handle Click event you should try this:
_loginButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Some method to do...
}
});
Hope it will help.
Related
I'm new to using the Roboelectric testing framework and the issue that I am having is not being able to build an activity. I used the same exact test in every class and they worked as expected, except for the CallingActivity that relies on being called by Handler.postDelayed which I believe is the problem.
This is the code that will create the CallingActivity:
btnCall.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new Handler().postDelayed(new Runnable()
{
#Override
public void run() {
Intent intent = new Intent(FakePhoneCallMenuActivity.this, CallingActivity.class);
intent.putExtra("callerName", nameEntryBox.getText().toString());
intent.putExtra("callerPhoneNum", phoneEntryBox.getText().toString());
intent.putExtra("callerVoice", voice);
startActivity(intent);
}
}, timeToStart);
}
});
This is test for the CallingActivity that is having issues working:
#RunWith(RobolectricTestRunner.class)
#Config(sdk = {Build.VERSION_CODES.O_MR1})
public class CallingTest {
private CallingActivity activity;
#Before
public void setUp() throws Exception {
activity = Robolectric.buildActivity(CallingActivity.class)
.create()
.start()
.resume()
.get();
}
#Test
public void acceptCallButtonClickShouldStartNewActivity() throws Exception {
ShadowActivity shadowActivity = shadowOf(activity);
ImageButton button = (ImageButton) shadowActivity.getContentView().findViewById(R.id.btnAcceptCall);
button.callOnClick();
Intent startedIntent = shadowActivity.getNextStartedActivity();
ShadowIntent shadowIntent = shadowOf(startedIntent);
assertEquals(FakePhoneCallMenuActivity.class, shadowIntent.getIntentClass());
}
}
The issue that I am recieving after trying to run this test is:
java.lang.Exception: Main looper has queued unexecuted runnables.
Help with this would be greatly appreciated!
Thanks
I'm an android beginner, I have some java knowledge, but i'm getting trouble with some android code.
In java we can use anonymous class to override methods of an interface.
I came across the following situation.
MyButton.setOnClickListener(New Button.OnClickListener{
#override
public void onClick(View view){
//some code
}
});
I was used to using the anonymous class like so,
Interface myInterface = new Interface(){
}
I can't just figure out what only New followed by the interface name means,inside a method.
It is a anonymous class without a variable name
MyButton.setOnClickListener(new Button.OnClickListener{
#override
public void onClick(View view){
//some code
}
});
is the same as
Button.OnClickListener listener = new Button.OnClickListener{
#override
public void onClick(View view){
//some code
}
});
MyButton.setOnClickListener(listener);
I've tried implementing an onClickListener on a CameraFragment, however, it never seems to be called. I am probably missing something quite simple. Does anyone have any ideas?
public class CWACCameraFragment extends CameraFragment implements OnClickListener {
//...
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
takePicture();
Toast.makeText(getActivity(),"click",
Toast.LENGTH_LONG).show();
}
Is there a way to ensure that the onClick event occurs?
In the demo app, I added the following to DemoCameraFragment:
#Override
public void onStart() {
super.onStart();
getView().setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.e(getClass().getSimpleName(), "got here");
}
});
}
Log messages showed up just fine. Hence, AFAICT, your approach works, so perhaps there is some bug in how you wired in the click listener.
I am developing an android application. Now i have created one function which create custom dialog box and i want this dialog box to display on every activity. So i need to call this function at every activity. But as the syntax of custom dialog (e.g. Dialog d = new Dialog(home.this)).home is the name of the activity where i have created the function so i am not ale to use this function in any other activity. And i haven't use android that much. So give me good example to solve my problem. Here is my code
here is sample code code of using AlertDialog in all activity.
crate one class file like as allmethod.java
and add this code in that class
public static void showAlert(Activity act,String msg)
{
AlertDialog.Builder alert = new AlertDialog.Builder(act);
alert.setMessage(msg).setPositiveButton("OK", new OnClickListener(){
#Override
public void onClick(DialogInterface dialog, int which)
{
}
}).show();
}
and you can use from any class like as
allmethod.showAlert(Activity,"Message");
In your case..
public void SearchDialog(Context ctx){
final Dialog dialog = new Dialog(ctx);
dialog.setContentView(R.layout.dialogsearch);
dialog.setTitle(" Enter The Text to Search");
dialog.setCancelable(true);
final EditText Text = (EditText) dialog.findViewById(R.id.EdText);
Button buttonOK = (Button) dialog.findViewById(R.id.btnOK);
buttonOK.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String SearchText = Text.getText().toString();
prefsPrivate =getSharedPreferences(Login.PREFS_PRIVATE,Context.MODE_PRIVATE);
Editor prefsPrivateEdit=prefsPrivate.edit();
prefsPrivateEdit.putString("Text",SearchText);
prefsPrivateEdit.commit();
Intent i = new Intent(ctx,SearchTask.class);
startActivity(i);
dialog.cancel();
}
});
Button buttonCancel = (Button) dialog.findViewById(R.id.btnCancel);
buttonCancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.cancel();
}
});
dialog.show();
}
Just add a Context parameter to your SearchDialog() constructor.
Make it like this:
public SearchDialog(Context context){
//....
}
You could either define your own Interface and implement for every class, or make the main Activity method static (as long as it wont need to access anything in dynamic objects that aren't method arguments).
final class Uutil {
public void static func() {
}
}
then do it in your classes:
class A {
public void f() {
Uutil.func();
}
}
I need help adding a background on android slider.java, so I want to have a background and to change it like this:
getBackground ( R.drawable_slider_bg);
if leftslider = PRESSED (getBackground = (R.drawable.slider_left_bg));
if rightslider = PRESSED (getBackground = (R.drawable.slider_right_bg));
Can someone help please?
// on slider.java
setBackgroundDrawable( R.drawable_slider_bg);
leftSlider.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
setBackgroundDrawable(R.drawable.slider_left_bg);
}
};
rightSlider.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
setBackgroundDrawable(R.drawable.slider_right_bg);
}
};