小编Rob*_*Rob的帖子

来自偏好xml的Mailto可能吗?

我正在尝试构建我的应用程序的首选项,我希望做一个"联系开发人员"区域,当点击它时,它会打开一个指向我的电子邮件.这可以单独从xml文件中执行,还是需要在主类中执行操作?

我在这里搜索了一下,但没有看到任何关于从XML做的事情,所以也许这不可能?以为我会把这个问题扔出去.

谢谢!

编辑:这是我实际上为将来寻找一些代码的人工作的方式:

import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;

public class Prefs extends PreferenceActivity {

@Override

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.layout.prefs);
    Preference mailTo = (Preference) findPreference("mailTo");


    mailTo.setOnPreferenceClickListener(new OnPreferenceClickListener() 
  {
   public boolean onPreferenceClick(Preference preference) 
   {
        // Preferences

        Intent mailto = new Intent(Intent.ACTION_SEND); 
        mailto.setType("message/rfc822") ; // use from live device
        mailto.putExtra(Intent.EXTRA_EMAIL, new String[]{"test@gmail.com"});
        mailto.putExtra(Intent.EXTRA_SUBJECT,"Subject Here");
        mailto.putExtra(Intent.EXTRA_TEXT,"Body Here");
        startActivity(Intent.createChooser(mailto, "Select email application."));
    return true;
   }
  });

}
Run Code Online (Sandbox Code Playgroud)

}

mailto android preferences android-intent

15
推荐指数
2
解决办法
3080
查看次数

点击导航抽屉关闭

我已经实现了导航抽屉,但是我在使其正常运行时遇到了一些麻烦.当我点击位置1或2时,它不会启动新片段.

MainActivity.java

public class MainActivity extends Activity {

    private DrawerLayout mDrawerLayout;
    private ListView mDrawerList;
    private ActionBarDrawerToggle mDrawerToggle;

    // nav drawer title
    private CharSequence mDrawerTitle;

    // used to store app title
    private CharSequence mTitle;

    // slide menu items
    private String[] navMenuTitles;
    private TypedArray navMenuIcons;

    private ArrayList<NavDrawerItem> navDrawerItems;
    private NavDrawerListAdapter adapter;

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

        Typeface tf = Typeface.createFromAsset(getAssets(),"Roboto-Light.ttf");
        TextView title = (TextView) findViewById(R.id.appTitle);
        TextView newRecord = (TextView) findViewById(R.id.newRecord);
        TextView pastRecords = (TextView) findViewById(R.id.pastRecords);
        TextView statistics = (TextView) …
Run Code Online (Sandbox Code Playgroud)

java android fragment navigation-drawer

4
推荐指数
1
解决办法
2709
查看次数

Android - 预填充数据库,插入或预加载?

我正在构建一个应用程序,该应用程序目前在其中一个表中有11列和120行文本数据.它可能是为用户预先填充的唯一表,但是,我试图弄清楚填充数据的最佳方法是什么.我看到了一些不同的选择.

  1. 在oncreate数据库期间运行insert语句
  2. 在assets文件夹中创建一个已有数据的表,并在创建应用程序时将其复制.

对于这样的事情,最佳做法是什么?随着时间的推移,数据库将更新几行.我看一个月可能有几行,没什么太大的.

任何帮助将不胜感激.

java android android-sqlite

3
推荐指数
1
解决办法
971
查看次数

在FragmentStatePagerAdapter NPE中运行数据库查询

我正在尝试对我的数据库运行查询以从我的数据库中获取一些数据(这会将页面更改为页面).我在Double balance = db.getSum(); 下面得到一个NullPointerException 是我的fragmentstatepageradapter的完整代码

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;


public class MyFragmentPagerAdapter extends FragmentStatePagerAdapter {

    int listSize;
    String[] tabNames;
    String tabName;
    protected Context mContext;

    /** Constructor of the class */
    public MyFragmentPagerAdapter(FragmentManager fm, Context c) {
        super(fm);
        mContext = c;
    }

    /** This method will be invoked when a page is requested to create */
    @Override
    public Fragment getItem(int arg0) {

        MainFragment mainFragment = new MainFragment();
        final DatabaseHelper db = new DatabaseHelper(mContext); …
Run Code Online (Sandbox Code Playgroud)

android nullpointerexception android-sqlite fragmentstatepageradapter

2
推荐指数
1
解决办法
6022
查看次数

AlertDialog - 尝试让警报工作

所以我在这里搜索了一些关于AlertDialog的问题,我不完全确定我在做什么,所以我很难将这些问题与我自己的例子联系起来.(我对这个整个Android编程还是新手,所以请耐心等待.)

我已经在public class _下定义了这个实现OnCLickListener的...

    public AlertDialog myAlertDialog;
Run Code Online (Sandbox Code Playgroud)

然后我在onClick下有这个

    public void onClick(View src) {

    switch(src.getId()){
    case R.id.buttonOk:
        if (score==0){
            AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this);
            myAlertDialog.setTitle("Title");
            myAlertDialog.setMessage("Message");
            myAlertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    return;
                } }); 
            myAlertDialog.show();
        }
Run Code Online (Sandbox Code Playgroud)

此行及其下方的行有错误:

myAlertDialog.setButton("OK", new DialogInterface.OnClickListener() {
Run Code Online (Sandbox Code Playgroud)

错误:

1st:此行的多个标记 - DialogInterface无法解析为类型 - 方法setButton(String,new OnClickListener(){})未定义类型

第二:DialogInterface无法解析为一个类型

任何人都可以告诉我,我做错了吗?

谢谢!

alert android dialog android-layout android-alertdialog

1
推荐指数
1
解决办法
9663
查看次数

请帮助我理解阅读偏好的一部分

所以我对java/android仍然有点新,我试图读取一个偏好值,但我试图理解它的每个部分,所以它对我来说更有意义......

SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
boolean soundEnabledPref = sharedPref.getBoolean("sound", soundEnabled);
Run Code Online (Sandbox Code Playgroud)

在getBoolean中,我试图理解第一个字符串是什么"声音",以及soundEnabled boolean的用途.

所以我已经声明soundEnabled作为布尔值顶部,我猜这是存储我正在检索的值的东西?

虽然"声音",第一个字符串的目的是什么?我想确保我正确地命名它,如果它用于存储某些东西,或者如果我用它引用某些东西,那么我可能需要将它命名为不同的东西.

我已经阅读了开发人员的文档,但仍然有点困惑,所以如果有人能给我一个快速的解释,我会非常感激!

java android boolean preferences

-1
推荐指数
1
解决办法
65
查看次数