小编Akh*_*hil的帖子

在Flutter中使用SafeArea

我试图了解Flutter中的SafeArea小部件.

SafeArea代码加入到扑图库应用程序在这里在github上展示 top:falsebottom:false随处可见.为什么在这些情况下需要将这些设置为假? 在此输入图像描述

flutter

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

选中listview中的复选框也会检查其他随机复选框

每当我检查列表视图中的复选框时,其他随机复选框也会被检查.这可能是由于listview的物品回收.

我也尝试android:focusable="false"按照某些地方的建议在我的布局中设置复选框,但是当选中其复选框时,仍然没有为行调用onListItemClick().只有当我点击其他地方时才会调用它.

我想要的是只有用户选中的复选框应保持检查,直到用户取消选中它们.

我在下面给出完整的代码,可以直接运行.

活动代码 - ProjActivity.java:

public class ProjActivity extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    PackageManager pm = getPackageManager();
    List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

    final CopyOfMyCustomAdapter a = new CopyOfMyCustomAdapter(this, packages);
    getListView().setAdapter(a);
}}
Run Code Online (Sandbox Code Playgroud)

最后,自定义布局文件 - testlayout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" 

>

<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:text="CheckBox" 
    android:focusable="false"
    />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher" 
    android:focusable="false"
    />
Run Code Online (Sandbox Code Playgroud)

更新:我的CustomAdapter在以下答案中的建议之后:

public class MyCustomAdapter extends ArrayAdapter<ApplicationInfo>  {

private …
Run Code Online (Sandbox Code Playgroud)

android android-listview

24
推荐指数
3
解决办法
3万
查看次数

即使应用程序被强制停止也会重新启动服务,即使在关闭应用程序后仍然在后台继续运行服务如何?

我正在尝试在后台运行服务.我的应用程序所做的是当用户检查复选框然后服务启动时以及取消选中时服务停止.哪个工作得很好.但问题是,当我从任务管理器关闭应用程序时,它也会停止服务.我想要的是即使它从任务管理器关闭后仍保持服务运行.然后,只有通过取消方框才能让用户自己停止该服务.

我怎样才能做到这一点?

这是我的代码

我的主要活动

public class SampleServiceActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final CheckBox cb = (CheckBox) findViewById(R.id.checkBox1);

    cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView,
                boolean isChecked) {

            if(isChecked) {
                Toast.makeText(getBaseContext(), "Checked", Toast.LENGTH_LONG).show();
                startService(new Intent(getBaseContext(), MyService.class));
            } else {
                Toast.makeText(getBaseContext(), "Unchecked", Toast.LENGTH_LONG).show();
                stopService(new Intent(getBaseContext(), MyService.class));
            }
        }

    });
}
}
Run Code Online (Sandbox Code Playgroud)

我的服务类

public class MyService extends Service {
Notify n = new Notify();
@Override
public IBinder …
Run Code Online (Sandbox Code Playgroud)

java android android-service

17
推荐指数
3
解决办法
3万
查看次数

访问联系人时的Android安全例外

这非常奇怪,我在论坛中搜索过.

在我的主类我有一个按钮onClick将启动联系人应用程序,如下所示.当我单击按钮时,会显示联系人列表,但只要点击联系人,就会抛出安全异常.

public void selectContacts(View v) {
        Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
        startActivityForResult(intent, PICK_CONTACT);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {

        case PICK_CONTACT:
            if (resultCode == Activity.RESULT_OK) {
                Uri contactData = data.getData();
                Cursor c = managedQuery(contactData, null, null, null, null);
                while (c.moveToNext()) {
                    String id = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));
                    String phoneNumber = getPhoneNumber(id);
                    listOfContacts.add(phoneNumber);

                }
            } else {
                System.out.println("User didn't pick a contact");
                finish();
            }
            break;
        }

        super.onActivityResult(requestCode, resultCode, data);
    }
Run Code Online (Sandbox Code Playgroud)

我检查了清单,并尝试了在应用程序,活动等中放置uses-permission标签的所有组合.但没有任何作用.这是我的清单.

<?xml version="1.0" …
Run Code Online (Sandbox Code Playgroud)

security android exception contacts

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

如何延迟代码执行(绘制路径)几秒钟?

这是关于加载的问题.我的应用程序应该等待3秒然后绘制路径.现在,加载消息框在3秒内出现,但应用程序不会等待3秒并立即绘制.我的编码有问题吗?

非常感谢!!

 public void drawpath(){
       // first to do some checking
    if (sourceLat.equals("22.3366467")  && destinationLat.equals("35.68449"))
        ShowMsgDialog("Please enter the starting point and destination");
    else if (sourceLat.equals("22.3366467") )
        ShowMsgDialog("Please enter the starting point by touch");
    else if (destinationLat.equals("35.68449") )
        ShowMsgDialog("Please enter the destination by touch");

    else if (pairs != null ){
        //  go to loading function
        loading();
        // Start to draw the path
        String[] lngLat = pairs[0].split(",");

        GeoPoint startGP = new GeoPoint((int) (Double.parseDouble(lngLat[1]) * 1E6), (int) (Double.parseDouble(lngLat[0]) * 1E6));

         mc = mapView.getController(); …
Run Code Online (Sandbox Code Playgroud)

android handler progressdialog delayed-execution

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

从 List&lt;String&gt; 添加或删除时不支持获取操作?

初学者 android 程序员,我想在用户单击列表项时从字符串列表中添加和删除项目,但在尝试执行此操作时出现操作不支持错误。请参阅以下代码以了解我想要做什么。

@Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        if(myList != null)
        {
            StringBuilder stringBuilder = new StringBuilder();
            if(myList.contains(mylist1.get(position).getPackageName()))
            {
                for(int i = 0; i < myList.size(); i++)
                {
                    if(myList.get(i).equals(mylist1.get(position).getPackageName()))
                        continue;
                    if((myList.size() - 1) != i)
                        stringBuilder.append(myList.get(i)).append(separator);
                    else
                        stringBuilder.append(myList.get(i));
                }
                editor.putString("mypreference", stringBuilder.toString());
                mylistt1.get(position).setDisabled(false);
       //error happens in following
                myList.remove(mylist1.get(position).getPackageName());
            }
      }
}
Run Code Online (Sandbox Code Playgroud)

这是日志猫

04-08 11:33:00.030: ERROR/AndroidRuntime(533): FATAL EXCEPTION: main
        java.lang.UnsupportedOperationException
        at java.util.AbstractList.remove(AbstractList.java:638)
        at java.util.AbstractList$SimpleListIterator.remove(AbstractList.java:75)
        at java.util.AbstractCollection.remove(AbstractCollection.java:229)
        at com.mypackage.myActivity.onListItemClick(myActivity.java:82)
        at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
        at …
Run Code Online (Sandbox Code Playgroud)

android list arraylist invalidoperationexception listactivity

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