Articles on Trending Technologies

Technical articles with clear explanations and examples

Playing an Arbitrary tone with Android?

Azhar
Azhar
Updated on 08-Jul-2020 331 Views

This example demonstrates how do I playing an arbitrary tone with android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.javaimport androidx.appcompat.app.AppCompatActivity; import android.media.AudioFormat; import android.media.AudioManager; import android.media.AudioTrack; import android.os.Bundle; import android.os.Handler; public class MainActivity extends AppCompatActivity {    private final int duration = 10;    private final int sampleRate = 8000;    private final int numSamples = duration * sampleRate;   ...

Read More

How to detect scroll up and scroll down in android listView?

Azhar
Azhar
Updated on 08-Jul-2020 1K+ Views

This example demonstrates how do I detect scroll up and down in android listView.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.javaimport androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.AbsListView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.ScrollView; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    ScrollView scrollView;    ListView listView;    String[] numbers = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "X", "11", "12", "13", ...

Read More

How to set the value for the attribute layout_weight for button in Android dynamically from java code?

Azhar
Azhar
Updated on 08-Jul-2020 2K+ Views

This example demonstrates how do I set the value for the attribute layout_weight for button in android dynamically from java code.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.javaimport androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.Button; import android.widget.LinearLayout; public class MainActivity extends AppCompatActivity {    LinearLayout linearLayout;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       linearLayout ...

Read More

How to resolve "Expected BEGIN_OBJECT but was BEGIN_ARRAY" using Gson in Java?

raja
raja
Updated on 08-Jul-2020 19K+ Views

While deserializing, a Gson can expect a JSON object but it can find a JSON array. Since it can't convert from one to the other, it can throw an error as "JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY" at the runtime.Exampleimport com.google.gson.Gson; public class GsonErrorTest {    public static void main(String args[]) throws Exception {       String json = "{\"employee\":[{\"name\":\"Raja Ramesh\", \"technology\":\"java\"}]}";       Gson gson = new Gson();       Software software = gson.fromJson(json, Software.class);       System.out.println(software);    } } class Software {    Employee employee; } class Employee {    String name; ...

Read More

How to serialize a JSON object with JsonWriter using Object Model in Java?

raja
raja
Updated on 08-Jul-2020 3K+ Views

The javax.json.JsonWriter interface can write a JSON object or array structure to an output source. The class javax.json.JsonWriterFactory contains methods to create JsonWriter instances. A factory instance can be used to create multiple writer instances with the same configuration. We can create writers from output source using the static method createWriter() of javax.json.Json class.Syntaxpublic static JsonWriter createWriter(Writer writer)In the below example, we can serialize a JSON object using the JsonWriter interface.Exampleimport java.io.StringWriter; import javax.json.Json; import javax.json.JsonObject; import javax.json.JsonObjectBuilder; import javax.json.JsonWriter; public class JsonWriterTest {    public static void main(String[] args) {       JsonObject jsonObj = Json.createObjectBuilder()                  .add("name", ...

Read More

How to make an Android SlidingDrawer slide out from the left?

Azhar
Azhar
Updated on 08-Jul-2020 415 Views

This example demonstrates how do I make an android slidingdrawer slide out from the left in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.                             >     Step 3 − Add the following code to src/MainActivity.javaimport androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       ...

Read More

How to create focusable editText inside ListView on Android?

Azhar
Azhar
Updated on 08-Jul-2020 1K+ Views

This example demonstrates how do I create a focusable editText inside ListView in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Create a new layout resource file and add the following code−         Step 4 − Add the following code to src/MainActivity.javaimport androidx.appcompat.app.AppCompatActivity; import android.annotation.SuppressLint; import android.app.LauncherActivity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.EditText; import ...

Read More

How can I get zoom functionality for images on Android?

Azhar
Azhar
Updated on 08-Jul-2020 507 Views

This example demonstrates how do I get zoom functionality for images in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.MotionEvent; import android.view.ScaleGestureDetector; import android.widget.ImageView; public class MainActivity extends AppCompatActivity {    private ScaleGestureDetector scaleGestureDetector;    private float scaleFactor = 1f;    private ImageView imageView;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       imageView = findViewById(R.id.imageView);       ...

Read More

How to add google search functionality in an android app?

Azhar
Azhar
Updated on 08-Jul-2020 1K+ Views

This example demonstrates how do I add google search functionality in an android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.javaimport androidx.appcompat.app.AppCompatActivity; import android.app.SearchManager; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; public class MainActivity extends AppCompatActivity {    EditText editText;    Button btnSearch;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);   ...

Read More

How to use date time picker in Android?

Azhar
Azhar
Updated on 07-Jul-2020 5K+ Views

This example demonstrates how do I use date and time picker in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.javaimport android.app.DatePickerDialog; import android.app.TimePickerDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.format.DateFormat; import android.view.View; import android.widget.Button; import android.widget.DatePicker; import android.widget.TextView; import android.widget.TimePicker; import java.util.Calendar; public class MainActivity extends AppCompatActivity implements DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener {    TextView textView;    Button button;    int day, month, ...

Read More
Showing 47071–47080 of 61,248 articles
Advertisements