Use of checkbox in Sketchware

Use of checkbox in Sketchware

Use of checkbox in Sketchware

Welcome my friend in KNHCenter. To day I discuss about check box.

Checkbox return type is true or false .when checkbox checked than it return true otherwise return false.

1.open sketchware app

2.Make new project

3.today my gole is make a project .When I pressed the a button .If check box is check than a message show me that check box is check . Otherwise show me a massege check box is unchecked.

4. Make following main.xml file like image which is given below

5. Create logi in onclik button

This

 

For android studio java and XML code is below:-

Main.Java:-

package com.my.newproject3;

import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.content.*;
import android.content.ClipboardManager;
import android.graphics.*;
import android.media.*;
import android.net.*;
import android.text.*;
import android.util.*;
import android.webkit.*;
import android.animation.*;
import android.view.animation.*;
import java.util.*;
import java.text.*;

 

public class MainActivity extends Activity {

private CheckBox checkbox1;
private CheckBox checkbox2;
private Button button1;

 

private ArrayList<HashMap<String, String>> fghji = new ArrayList<>();

private Intent a = new Intent();

 

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initialize();
initializeLogic();
}

private void initialize() {
checkbox1 = (CheckBox) findViewById(R.id.checkbox1);
checkbox2 = (CheckBox) findViewById(R.id.checkbox2);
button1 = (Button) findViewById(R.id.button1);

 

button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _v) {
if (checkbox2.isChecked()) {
showMessage(“check box is ckeck”);
}
else {
showMessage(“check box is unckeck”);
}
}
});

}

private void initializeLogic() {

}

 

 

 

// created automatically
private void showMessage(String _s) {
Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
}

private int getRandom(int _minValue ,int _maxValue){
Random random = new Random();
return random.nextInt(_maxValue – _minValue + 1) + _minValue;
}

public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
ArrayList<Double> _result = new ArrayList<Double>();
SparseBooleanArray _arr = _list.getCheckedItemPositions();
for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
if (_arr.valueAt(_iIdx))
_result.add((double)_arr.keyAt(_iIdx));
}
return _result;
}

private float getDip(int _input){
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics());
}

private int getDisplayWidthPixels(){
return getResources().getDisplayMetrics().widthPixels;
}

private int getDisplayHeightPixels(){
return getResources().getDisplayMetrics().heightPixels;
}

 

}
<LinearLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”
>
<CheckBox
android:id=”@+id/checkbox1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:padding=”8dp”
android:text=”CheckBox”
android:textSize=”12sp”
android:textColor=”#000000″
android:scaleX=”0.0″
android:checked=”true”
/>
<Button
android:id=”@+id/button1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:padding=”8dp”
android:text=”for checking of ckeckbox click here”
android:textSize=”12sp”
android:textColor=”#000000″
/>
<CheckBox
android:id=”@+id/checkbox2″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:padding=”8dp”
android:text=”CheckBox”
android:textSize=”12sp”
android:textColor=”#000000″
/>
</LinearLayout>
<LinearLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:orientation=”vertical”
>
<Button
android:id=”@+id/button1″
android:focusable=”false”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:padding=”8dp”
android:text=”Button”
android:textSize=”12sp”
android:textColor=”#000000″
/>
<ImageView
android:id=”@+id/imageview1″
android:focusable=”false”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:src=”@drawable/default_image”
android:scaleType=”center”
/>
</LinearLayout>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.my.newproject3″>

 

<application android:allowBackup=”true”
android:label=”hhh”
android:icon=”@drawable/app_icon”
android:name=”.SketchApplication”
android:theme=”@style/AppTheme”>

<activity
android:name=”.MainActivity”
android:configChanges=”orientation|screenSize”
android:screenOrientation=”portrait”
>
<intent-filter>
<action android:name=”android.intent.action.MAIN”/>
<category android:name=”android.intent.category.LAUNCHER”/>
</intent-filter>
</activity>
<activity android:name=”.DebugActivity” android:screenOrientation=”portrait”/>
</application>

</manifest>

Comments

Popular posts from this blog

How to enable uploading in sketchware

Animation object use in sketchware

How to a Media Player on android mobile