[Q] PreferenceActivity with Checkboxpreference - General Questions and Answers

Hello,
I am french , excuse me for me english .
I'm beginner in java, I begin to make a class for preferences (PreferenceActivity) however I do not know how to implement this type of a class checkboxpreference. For example if possible I would like it like this:
Code:
if (IsChecked) {
Toast.makeText (getApplicationContext (), "On", Toast.LENGTH_LONG) show ().
} Else {
Toast.makeText (getApplicationContext (), "Off", Toast.LENGTH_LONG) show ().}
.
My class :
Code:
package com.root.tools.open;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.;
import android.content.;
import android.util.;
import android.widget.CompoundButton.;
import android.view.;
import android.preference.;
public class Preference extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference);
}}
How implent this method ?
Thank You so much !

Related

[Q] First program (error message)

Hi, i know a little bit of java so i was thinking start to create program to my android phone.
but even "hello world" program can't run, i get message:
An internal error occurred during: "Launching New_configuration".
Path for project must have only one segment.
How to fix this ?
Thanks
so no one knows how to fix this ?
I might be helpfull if you would've posted the code you have
it's from google site android hello world program
nevertheless :
package com.android.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}

[Resolved] [Q] Android App Problem (Linking list items to the android market)

Hey guys,
I need some help with my first app.
I cannot post this in the Anddev section because of my low post count, so I apologize that this goes here.
I want to link some list positions to the respective android market pages. My current code looks like this:
Code:
package com.asm.reader;
import java.util.ArrayList;
import java.util.Arrays;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
public class TitlesActivity extends ListActivity {
/** Called when the activity is first created. */
String[] links = {
"Get Full Version", "Get Reading Sample 2", "Get Reading Sample 3", "Get Reading Sample 4", "Get Reading Sample 5",
"Get Story 2", "Get Story 3", "Get Story 4", "Get Story 5"};
private ArrayAdapter<String> adapter;
private String selectedItem;
private final Context context = this;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
OnItemClickListener itemListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View arg1, int position,
long arg3) {
}
};
ArrayList<String> list = new ArrayList<String>(Arrays.asList(links));
adapter = new ArrayAdapter<String>(
this,
android.R.layout.simple_list_item_1,
list);
setListAdapter(adapter);
getListView().setOnItemClickListener(itemListener);
}
}
The dev guide says I have to do this:
Code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.android.example"));
startActivity(intent);
But how do I set it with the right position?
Thanks a lot in advance, I hope you guys can help me out a little bit.
-----
edit: i got it
Please post how you did it!

[APP]2 java files dosen't work

Hi people.
I'm new in JAVA develop, and I'm trying do a simple game.
I tryed to work with 2 separated java files, but I don't know what I'm doing wrong. Example:
File "TesteActivity.java"
package pack.teste;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class TesteActivity extends Activity {
test1 test = new test1();
public TextView text;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text = (TextView)findViewById(R.id.maoe);
text.setText(test.hahae);
}
}
File "test1.java"
package pack.teste;
public class test1 {
TesteActivity test = new TesteActivity();
public String hahae = "maoe";
}
And dosen't work. Somebody can help me?
Thanks

[Q] google map v1

Hi,
I am trying to load google map v1 on android application but only able to see grid. no map. Guide please what thing i am missing?
My main activity file is:
**************************************************************************
package com.example.mymapactivity;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MyMapActivity extends Activity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
@suppressLint("NewApi")
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_map);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
@override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my_map, menu);
return true;
}
}
Please guide
Thanks

API 19 and Bluetooth Low Energy

I am currently working on a project to connect a Google Glass Explorer Edition (Android Kitkat and therefore API 19) to an Arduino board emitting data in BLE.
I have checked that this is possible and I have found and installed an APK that manages to make the link. However, I want to make a slightly different application.
The application I want to make has a splash screen and a main activity displaying the different values on TextView. This part is already working.
Splash Screen:
Java:
package com.example.flyin_glass;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AppCompatActivity;
/* loaded from: classes.dex */
public class SplashScreenActivity extends AppCompatActivity {
/* JADX INFO: Access modifiers changed from: protected */
@Override // androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, android.app.Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
Runnable runnable = new Runnable() { // from class: com.example.myapplication.SplashScreenActivity.1
@Override // java.lang.Runnable
public void run()
{
Intent intent = new Intent(SplashScreenActivity.this.getApplicationContext(), MainActivity.class);
SplashScreenActivity.this.startActivity(intent);
SplashScreenActivity.this.finish();
}
};
new Handler().postDelayed(runnable, 3000L);
}
}
Main activity :
Java:
package com.example.flyin_glass;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.*;
import android.bluetooth.le.*;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.content.Context;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
My goal would be to code (in main activity) the management of the BLE, i.e. the automatic connection to my Arduino (which has a specific UUID) as well as the data retrieval and display in TextView.
Being a novice in Android development, the task of managing the BLE is very complex for me. Do you have any advice?
Thank you in advance.
GAUBERT36

Categories

Resources