Widget - TextSwitcher

final String strTextSwitcher[] = {"Text Switcher 1", "Text Switcher 2", "Text Switcher 3", "Text Switcher 4", "Text Switcher 5"};

final int currentIndex = -1;

final TextSwitcher textSwitcher = new TextSwitcher(MainActivity.this);
textSwitcher.setLayoutParams(new LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT));
linear1.addView(textSwitcher);


textSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
public View makeView() {
TextView t = new TextView(MainActivity.this);
t.setGravity(Gravity.TOP | Gravity.CENTER);
t.setTextSize(36);

return t;

}

});

textSwitcher.setCurrentText("click Button");


//button prev
button1.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

if (currentIndex>0)

currentIndex = currentIndex-1;

textSwitcher.setText(strTextSwitcher[currentIndex]);
}

});

//button next
button2.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

if (currentIndex<strTextSwitcher.length-1)

currentIndex = currentIndex+1;

textSwitcher.setText(strTextSwitcher[currentIndex]);

}

});

Komentar

Cara pembuatan Apps paling Populer

Create Stopwatch App in Android using Sketchware

How to enable download in webview in Sketchware apps?

TextInputLayout in Sketchware

Create Stopwatch App in Android using Sketchware

How to integrate Admob Ads in Sketchware project using AIDE?

How to find and​ highlight a word in a text field in Sketchware?

Code for implementing Notifications in Sketchware

A Flash Light App in Sketchware

Create a Stopwatch App using Chronometer in Sketchware

Create app to save all passwords, protected using voice key