小编mat*_*ash的帖子

将ListView项的id传递给ActionMode.Callback对象

所以我现在的问题是,现在我长时间点击ListView中的一个项目,它会调出一个上下文操作栏.传递给onItemLongClick的id是我想在mActionModeCallback的ActionItemClicked()方法中使用的变量.这似乎是一个相当常见的过程,因为如果用户正在编辑项目列表,您将希望在用户单击"编辑"或"删除"操作时以某种方式访问​​数据库中该行的ID.

listView.setOnItemLongClickListener(new OnItemLongClickListener() {
    public boolean onItemLongClick(AdapterView<?> p, View view, int pos, long id) {

        //The id of the row in the database
        long variableThatIWantToPassToCallback = id; 
        mActionMode = getActivity().startActionMode(mActionModeCallback);
        view.setSelected(true);
        return true;
    }
});

private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {

    public boolean onCreateActionMode(ActionMode mode, Menu menu) {}

    public boolean onPrepareActionMode(ActionMode mode, Menu menu) {}

    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
        //I would like access to the id of the clicked item here, NOT item.getItemId()
    }

    public void …
Run Code Online (Sandbox Code Playgroud)

android contextual-action-bar

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

java.lang.ClassCastException:java.io.File无法强制转换为android.os.Parcelable

我正在尝试创建文本文件共享它(通过蓝牙,电子邮件..)

File file = null;
try {
    file = createFile2(json);
} catch (IOException e) {
    e.printStackTrace();
}

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, file);
shareIntent.setType(getString(R.string.share_contact_type_intent));
Run Code Online (Sandbox Code Playgroud)

这是createFile2()的乐趣:

 public File createFile2(String text) throws IOException {
        File file = new
                File(getFilesDir() + File.separator + "MyFile.txt");

        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
        bufferedWriter.write(text);
        bufferedWriter.close();
        return file;
    }
Run Code Online (Sandbox Code Playgroud)

logcat的:

Bundle? Key android.intent.extra.STREAM expected Parcelable but value was a java.io.File.  The default value <null> was returned.
Bundle? Attempt to cast generated …
Run Code Online (Sandbox Code Playgroud)

serialization android file android-sharing

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

如何创建 Notification.Action 并将其添加到自定义通知

我在这里按照谷歌的说明https://developer.android.com/training/wearables/notifications/creating.html

然而,不出所料,他们的代码不起作用。具体来说,我正在尝试这样做:

// Build the notification and add the action via WearableExtender
        Notification notification =
                new Notification.Builder(context)
                        .setSmallIcon(R.drawable.buzz_icon)
                        .setContentTitle("Buzz")
                        .setContentText("OpenBuzz")
                        .extend(new Notification.WearableExtender().addAction(action))
                        .build();
Run Code Online (Sandbox Code Playgroud)

我想要一个特定于可穿戴设备的操作,所以我别无选择,只能使用Notification.WearableExtender(). 但它的 addAction 方法只接受一个动作作为它的参数。这是我创建动作的代码:

            Notification.Action action =
                Notification.Action.Builder(R.drawable.buzz_icon, actionIntent.toString(), pendingIntent);
Run Code Online (Sandbox Code Playgroud)

哪个不起作用,因为 Android Studio 说“预期方法调用”如何成功创建Notification.Action? 或者我还可以如何向我的通知添加可穿戴设备的特定操作?

android android-notifications android-support-library wear-os

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

如何在64位Windows上安装32位Android Studio?

http://developer.android.com/sdk/index.html#Other上的下载页面没有显示任何明确的32位和64位下载,所以我猜测安装程序会自动在64位系统上安装64位版本.有没有办法改写这个?

android android-studio

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

如何确定文本何时被选中 [Android [EditText]]

是否可以确定何时选择文本,何时不选择?

我在谷歌搜索和我的find onSelectionChanged()方法或setOnLongClickListener()确定用户longClick何时选择 editText 所以当他进行选择时,但在这两种情况下,它都无法帮助我确定用户何时未选择任何文本(我可以将按钮设置为不可见)。 .

java android textselection android-edittext

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

如何确定我是否在Android Wear中运行?

我在Android Studio中有一个移动和磨损模块,他们都使用"核心"代码库...在核心代码中,我如何确定我的代码是否在"移动"模块的"磨损"上运行?我应该使用屏幕尺寸吗?

android wear-os

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

2个半圆圈围绕一个按钮

我正在尝试制作一个看起来像这样的布局.

在此输入图像描述

我正在使用github的 TriggerTrap/SeekArc .这是我的xml.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:seekarc="http://schemas.android.com/apk/res/com.triggertrap.sample"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@android:color/black"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <FrameLayout
        android:id="@+id/seekArcContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <com.triggertrap.seekarc.SeekArc
            android:id="@+id/seekArc1"
            android:layout_width="300dp"
            android:layout_height="300dp"
            android:layout_gravity="center"
            android:padding="20dp"
            seekarc:arcColor="#808080"
            seekarc:clockwise="true"
            seekarc:max="500"
            seekarc:progressColor="@android:color/white"
            seekarc:rotation="275"
            seekarc:startAngle="0"
            seekarc:sweepAngle="175"
            seekarc:thumb="@drawable/custom_seek_arc_control_selector"
            seekarc:touchInside="false" />


        <com.triggertrap.seekarc.SeekArc
            android:id="@+id/seekArc2"
            android:layout_width="300dp"
            android:layout_height="300dp"
            android:layout_gravity="center"
            android:layout_marginTop="10dp"
            android:padding="20dp"
            seekarc:arcColor="#808080"
            seekarc:clockwise="true"
            seekarc:max="500"
            seekarc:progressColor="@android:color/white"
            seekarc:rotation="95"
            seekarc:startAngle="0"
            seekarc:sweepAngle="175"
            seekarc:thumb="@drawable/custom_seek_arc_control_selector"
            seekarc:touchInside="false" />

        <Button 
            android:id="@+id/btn"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_gravity="center"
            android:background="@drawable/scrubber_pressed"/>
    </FrameLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

现在,问题是,因为我使用的是框架布局,所以只能点击一个seekarc. 如果我将seekarc更改为线性布局,整个布局会像这样扭曲.

在此输入图像描述

现在一切都是可点击的,但设计已经完成.任何人都可以告诉我如何让它工作,使按钮以及两个seekarc都是可触摸的,而且设计仍然不受影响.

java xml android android-layout

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

LINQ,如何使用"where"条件获取Max ID

我已经搜索了堆栈溢出,但只查找了最大ID的示例,我想查找某些特定条件的最大ID.像这样的东西

var nRow = from p in ctx.FormControls
.          where p.FormObjectsId == FormID
.          select Max(p.Id);
Run Code Online (Sandbox Code Playgroud)

怎么做 ?

c# linq

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

无法从类型Activity错误中对非静态方法findViewById(int)进行静态引用

嗨即时通讯在eclipse上制作一个计算器,我正在按照这个教程完成所有内容,就像在视频中一样,但由于某些原因我得到这个"无法从类型活动中对静态方法findViewById(int)进行静态引用"错误

public PlaceholderFragment() {

    int counter;
    Button add, sub;
    TextView display;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);
        counter = 0;
        add = (Button) findViewById(R.id.bAdd);
        sub = (Button) findViewById(R.id.bSub);
        display = (TextView) findViewById(R.id.tvDisplay);
        add.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                counter += 1;
                display.setText("Your total is " + counter);
            }
        });
        sub.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method …
Run Code Online (Sandbox Code Playgroud)

android android-fragments

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

Android 将货币 TextView 转换回双倍

我有一个名为 cardBalance 的 TextView

cardBalance = (TextView) findViewById(R.id.textViewCardBalance);
Run Code Online (Sandbox Code Playgroud)

我像这样设置了 cardBalance 的文本

double amount = 109.00;
NumberFormat baseFormat = NumberFormat.getCurrencyInstance();
String moneyString = baseFormat.format(amount)
cardBalance.setText(moneyString);
Run Code Online (Sandbox Code Playgroud)

这工作正常并根据需要显示 $ 符号,我现在的问题是如何获得这个值并将其转换回两倍?

我尝试了以下但没有成功

double bal = Double.parseDouble(cardBalance.getText().toString());
Run Code Online (Sandbox Code Playgroud)

如何在没有 $ 符号的情况下取回双倍值

java android number-formatting

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