小编TKu*_*mar的帖子

为什么在java中有两种使用线程的方法?

我知道有两种方法可以在java中使用线程:

  1. 实现Runable
  2. 扩展线程

我也知道实现 Runable比扩展Thread更好 .

但为什么有两种方式 - 为什么不只有一种?

如果实现Runnable是一种更好的方法,为什么还有其他选择呢?

只有一个选项会有什么问题?

java inheritance multithreading interface

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

如何在Android Marshmallow中创建wifi网络共享热点?

我尝试使用以下代码在Android Marshmallow中创建wifi tethering Hotspot.

public class WifiAccessManager {

    private static final String SSID = "1234567890abcdef";

    public static boolean setWifiApState(Context context, boolean enabled) {
        //config = Preconditions.checkNotNull(config);
        try {
            WifiManager mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            if (enabled) {
                mWifiManager.setWifiEnabled(false);
            }
            WifiConfiguration conf = getWifiApConfiguration();
            mWifiManager.addNetwork(conf);

            return (Boolean) mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class).invoke(mWifiManager, conf, enabled);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public static WifiConfiguration getWifiApConfiguration() {
        WifiConfiguration conf = new WifiConfiguration();
        conf.SSID = SSID;
        conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
        return conf;
    }
}
Run Code Online (Sandbox Code Playgroud)

}

但它显示以下权限问题.. …

android android-wifi tethering android-6.0-marshmallow

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

如何从列表视图中拖动项目并将其放在外部textView上?

我正在尝试实现android的拖放示例.经过长时间按下一个项目后,我将其拖动到目标水平并放在那里.我在某种程度上是成功的.但我想要一些不同的东西.我做过这样的事...... 在此输入图像描述

但我想将所有项目添加到listView中,并且在长按listview后我将拍摄一个项目,然后我将项目拖动到目标级别并将其放在那里.我想要这样的东西.. 在此输入图像描述

我的代码如下:

public class MainActivity extends Activity {



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






    findViewById(R.id.mango).setOnLongClickListener(longListen);
    findViewById(R.id.orange).setOnLongClickListener(longListen);
    findViewById(R.id.apple).setOnLongClickListener(longListen);
    findViewById(R.id.banana).setOnLongClickListener(longListen);

    findViewById(R.id.drop_here).setOnDragListener(DropListener);

    listview.setOnItemLongClickListener(new OnItemLongClickListener() {

        public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                int pos, long id) {
            // TODO Auto-generated method stub

            Log.i("long clicked","pos"+" "+pos);

            return true;
        }
    }); 
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

OnLongClickListener longListen = new OnLongClickListener() …
Run Code Online (Sandbox Code Playgroud)

android listview drag-and-drop

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

为什么我的Android Listview不滚动?

我用一些项目做了一个xml显示.但我的那个xml的listView不滚动.我做了一个scrollView,listView在scrollView里面,这是一个问题吗?如果我设计显示并将listView保持在scrollView外侧,则lisViw不会显示在我的Android设备显示屏上.我需要这样一个显示器,需要一个scrollView和滚动列表视图.我的代码如下.

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >

<LinearLayout 
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/head_logo" >
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/cardlistButton"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/head_menu04" />

    <View
        android:layout_width="1dip"
        android:layout_height="fill_parent"
        android:background="#ffffff" />

    <Button
        android:id="@+id/cameraButton"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/head_menu02" />

    <View
        android:layout_width="1dip"
        android:layout_height="fill_parent"
        android:background="#ffffff" />

    <Button
        android:id="@+id/homeButton"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/head_menu03" />
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/title_detail"
    android:gravity="right|center_vertical" >
</LinearLayout>

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        android:gravity="center"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dip"
            android:layout_marginRight="15dip"
            android:orientation="vertical" …
Run Code Online (Sandbox Code Playgroud)

xml android listview scrollview

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