Skip to content

Commit

Permalink
Merge pull request #2 from Tobibur/WithSingleChoiceRadioButton
Browse files Browse the repository at this point in the history
With single choice radio button
  • Loading branch information
Tobibur authored Aug 6, 2018
2 parents 4ed7beb + 98b5cb8 commit 1dced06
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,20 @@ PrintArray.setBoxTitle("Your String here for title");
### 2. Call this method below Onclick of a button :

```Java
PrintArray.diaBox(Button symp, String[] listItems, Context context)
//For MultiChoice Checkbox Dialog
PrintArray.diaCheckBox(Button symp, String[] listItems, Context context)
```

```Java
//For SingleChoice RadioButton Dialog
PrintArray.diaRadioBox(Button symp, String[] listItems, Context context)
```

## Sreenshots:

<img src="images/demo1.png" width="214"> <img src="images/demo2.png" width="214">
<img src="images/demo3.png" width="214"> <img src="images/demo4.png" width="214">
<img src="images/a.png" width="214"> <img src="images/b.png" width="214">
<img src="images/c.png" width="214"> <img src="images/d.png" width="214">
<img src="images/e.png" width="214">


[![](https://jitpack.io/v/Tobibur/PrintArray.svg)](https://jitpack.io/#Tobibur/PrintArray)
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ android {
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':printarray')
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,35 @@

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.example.tobibur.printarray.PrintArray;

public class MainActivity extends AppCompatActivity {

String[] listItems = {"Apple", "Mango", "Banana"};
Button mCheckButton, mRadioButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mCheckButton = findViewById(R.id.button);
mCheckButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PrintArray.diaCheckBox(mCheckButton,listItems,MainActivity.this);
}
});

mRadioButton = findViewById(R.id.button2);
mRadioButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PrintArray.diaRadioBox(mRadioButton,listItems,MainActivity.this);
}
});
}
}
26 changes: 23 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,33 @@
android:layout_height="match_parent"
tools:context="com.example.tobibur.printarrayexample.MainActivity">

<TextView
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:text=" CheckBox Dialog"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.332" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="RadioButton Dialog"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button"
app:layout_constraintVertical_bias="0.208" />

</android.support.constraint.ConstraintLayout>
Binary file added images/a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/demo1.png
Binary file not shown.
Binary file removed images/demo2.png
Binary file not shown.
Binary file removed images/demo3.png
Binary file not shown.
Binary file removed images/demo4.png
Binary file not shown.
Binary file added images/e.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.widget.Button;
import android.widget.Toast;

import java.util.ArrayList;

Expand All @@ -12,13 +14,18 @@ public class PrintArray {
private static ArrayList<Integer> mUserItems;
private static String title_default = "Please select the items";

private static String singleChoiceValue = null;
private static int singleCheckedItem = 0;

private static final String TAG = "PrintArray";

// setting AlertDialog title
public static void setBoxTitle(String title){
title_default = title;
}

// AlertDialog with checkBox method
public static void diaBox(final Button symp, final String[] listItems, Context context){
// AlertDialog with CheckBox method
public static void diaCheckBox(final Button button, final String[] listItems, Context context){
checkedItems = new boolean[listItems.length];
mUserItems = new ArrayList<>();
AlertDialog.Builder mBuilder = new AlertDialog.Builder(context);
Expand Down Expand Up @@ -48,7 +55,7 @@ public void onClick(DialogInterface dialogInterface, int which) {
no = no + ", ";
}
}
symp.setText(item);
button.setText(item);
}
});

Expand All @@ -65,12 +72,53 @@ public void onClick(DialogInterface dialogInterface, int which) {
for (int i = 0; i < checkedItems.length; i++) {
checkedItems[i] = false;
mUserItems.clear();
symp.setText("");
button.setText("");
}
}
});

AlertDialog mDialog = mBuilder.create();
mDialog.show();
}

// AlertDialog with RadioButton method
public static void diaRadioBox(final Button button, final String[] listItems, Context context){

AlertDialog.Builder mBuilder = new AlertDialog.Builder(context);
mBuilder.setTitle(title_default);
mBuilder.setSingleChoiceItems(listItems,singleCheckedItem, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
singleCheckedItem = i;
Log.d(TAG, "onClick: "+listItems[i]);
singleChoiceValue = listItems[i];
button.setText(singleChoiceValue);
}
});
mBuilder.setCancelable(false);
mBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {

button.setText(singleChoiceValue);
}
});

mBuilder.setNegativeButton("Dismiss", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});

mBuilder.setNeutralButton("Clear all", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
singleCheckedItem = 0;
}
});

AlertDialog mDialog = mBuilder.create();
mDialog.show();
}
}

0 comments on commit 1dced06

Please sign in to comment.