小编Dan*_*iel的帖子

当ListView为空时Android显示文本

我正在设置一个TextViewid,@android:id/empty以便在没有项目时显示消息ListView.但是,TextView即使ListView在项目出现之前有项目,也会显示此信息.

我怎样才能使它只在没有元素时显示ListView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<ListView
    android:id="@android:id/list"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:dividerHeight="1dp" >
</ListView>

<TextView 
    android:id="@android:id/empty"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/empty_list" />

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

PS:我正在使用a LoaderSimpleCursorAdaptera ListFragment.

android android-listview

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

Gradle无法与"无法找到可选库"同步

我不得不重新安装我的系统,今天当我尝试与gradle同步时,我在Android Studio中收到此错误:

Warning: Unable to find optional library: org.apache.http.legacy
Run Code Online (Sandbox Code Playgroud)

我的项目是:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}
Run Code Online (Sandbox Code Playgroud)

我的模块是gradle:

apply plugin: 'android'

android {
    useLibrary  'org.apache.http.legacy'

    compileSdkVersion 23
    buildToolsVersion '23.0.2'
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 23
    }
    buildTypes {
        release {
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.android.support:appcompat-v7:23.1.1'
}
Run Code Online (Sandbox Code Playgroud)

来自谷歌文档:

要继续使用Apache HTTP API,必须首先在build.gradle文件中声明以下编译时依赖项:

android {
    useLibrary 'org.apache.http.legacy'
} …
Run Code Online (Sandbox Code Playgroud)

android gradle android-studio build.gradle

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

适用于3.0之前版本的Android操作栏批量选择

我有一个ListView我想要启用批量选择的.对于Android 3.0及以上版本,我添加了一个模态多选项ListView并设置了多选模式监听器.

如何为3.0之前的Android版本(有或没有第三方库)做同样的事情?我看过ActionBarSherlock,但我没有在任何样本中找到此功能,也没有在网上搜索信息.

PS:当用户点击ListView我想要执行不同操作的项目时,需要长按批次选择(或单个项目选择).

3.0之前的版本可以追溯到API 7.

android listview actionbarsherlock android-actionbar

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

为什么即使缺少return语句,C语言中的程序也会编译?

我在C中实现了一些基本的数据结构,我发现如果我从函数中省略了返回类型并调用该函数,则编译器不会生成错误.我编译cc file.c并没有使用-Wall(所以我错过了警告)但在其他编程语言中这是一个严重的错误,程序将无法编译.

根据Graham Borland的要求,这是一个简单的例子:

int test() 
{
  printf("Hi!");
}

int main() 
{ 
    test();
}
Run Code Online (Sandbox Code Playgroud)

c

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