小编Rag*_*dan的帖子

在android中将时间戳转换为当前日期

我在显示日期时遇到问题,我的时间戳为1379487711,但实际时间是9/18/2013 12:31:51 PM,但它显示时间为17-41-1970.如何将其显示为当前时间.

为了显示时间我使用了以下方法:

private String getDate(long milliSeconds) {
    // Create a DateFormatter object for displaying date in specified
    // format.
    SimpleDateFormat formatter = new SimpleDateFormat("dd-mm-yyyy");
    // Create a calendar object that will convert the date and time value in
    // milliseconds to date.
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis((int) milliSeconds);
    return formatter.format(calendar.getTime());
} 
Run Code Online (Sandbox Code Playgroud)

java android timestamp date

43
推荐指数
4
解决办法
7万
查看次数

添加边界以避免在特定区域外滑动

我的应用程序显示了一张地图,我希望用户无法滑过某个区域.所以我试图添加边界,但它会使应用程序崩溃.这是工作代码:

public class MapViewer extends Activity implements OnInfoWindowClickListener {
    private LatLng defaultLatLng = new LatLng(42.564241, 12.22759);
    private GoogleMap map;
    private int zoomLevel = 5;
    private Database db = new Database(this);

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapviewer);

        try {
            map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
            if (map != null) {
                map.setMyLocationEnabled(true);
                map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
                map.getUiSettings().setRotateGesturesEnabled(false);

                map.moveCamera(CameraUpdateFactory.newLatLngZoom(defaultLatLng, zoomLevel));

                this.addMerchantMarkers(new MarkerOptions());

                map.setOnInfoWindowClickListener(this);
            }
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onPause() {
        if (map != null) {
            map.setMyLocationEnabled(false);
            map.setTrafficEnabled(false);
        }
        super.onPause();
    } …
Run Code Online (Sandbox Code Playgroud)

android google-maps-android-api-2

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

android java.lang.IllegalStateException:无法从CursorWindow读取第0行,第0列

我正在开发一个应用程序,它下载一些文件并将它们的文本保存在file_content字段中.文件大小可能从几KB到10 MB不等.该应用程序适用于所有尺寸,同时保存.在long file_content记录上使用select语句时会发生此问题.它给

java.lang.IllegalStateException:无法从CursorWindow读取第0行col 0

何时获取此类行.字段内容大小有限制吗?如果是这样,那么为什么它让我们在检索时保存并给出错误?这是我的代码剪切,提取行:

public String getFileContent(MyFile gc) {
        if(!isDBOpen()) {
            open();
        }
        try {
            String mQuery = "SELECT * FROM " + DBOpenHelper.TABLE_SAVED_FILES + " WHERE " + DBOpenHelper.COLUMN_ID + " = " + gc.id;
            Cursor mCursor = database.rawQuery(mQuery, null);
            if(mCursor.getCount() <= 0) {
                return null;
            }
            if(mCursor.moveToFirst()) {
                return getCursorRowContent(mCursor);
            }
        } catch (Exception e) {
            e.getMessage();
        }
        return null;
    }

    private String getCursorRowContent(Cursor mCursor) throws Exception {
        return mCursor.getString(mCursor.getColumnIndex(DBOpenHelper.COLUMN_FILE_CONTENT));
    }
Run Code Online (Sandbox Code Playgroud)

知道发生了什么事吗?我已经在2到3台设备上进行了测试.

Logcat输出:

01-29 13:41:56.520: W/CursorWindow(4121): …
Run Code Online (Sandbox Code Playgroud)

sqlite android android-cursor

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

找不到com.google.android.gms.location.LocationClient类(android)

我从http://developer.android.com/training/location/retrieve-current.html下载了一个演示项目,我想我没有丢失任何步骤; 但我找不到哪个jar文件包含"com.google.android.gms.location.LocationClient.class"文件

我们发现所有"google-play-services.jar"和"maps.jar"以及"android.jar(所有版本)"都不包含"LocationClient.class"?

android location

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

Android java.lang.ArrayIndexOutOfBoundsException:length = 10; 指数= 10

我很难搞清楚这一个.我无法在手机上重现(nexus 4).似乎没有影响所有设备,但我有足够的报告,看到它继续发生令人沮丧.

java.lang.ArrayIndexOutOfBoundsException: length=10; index=10
at android.text.StaticLayout.calculateEllipsis(StaticLayout.java:938)
at android.text.StaticLayout.out(StaticLayout.java:859)
at android.text.StaticLayout.generate(StaticLayout.java:524)
at android.text.StaticLayout.<init>(StaticLayout.java:147)
at android.widget.TextView.makeSingleLayout(TextView.java:6583)
at android.widget.TextView.makeNewLayout(TextView.java:6429)
at android.widget.TextView.onMeasure(TextView.java:6807)
at android.view.View.measure(View.java:16047)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1232)
at android.widget.TableRow.onMeasure(TableRow.java:114)
at android.view.View.measure(View.java:16047)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.TableLayout.measureChildBeforeLayout(TableLayout.java:464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.TableLayout.measureVertical(TableLayout.java:476)
at android.widget.TableLayout.onMeasure(TableLayout.java:439)
at android.view.View.measure(View.java:16047)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16047)
at android.widget.ListView.measureScrapChild(ListView.java:1190)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1255)
at android.widget.ListView.onMeasure(ListView.java:1165)
at android.view.View.measure(View.java:16047)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16047)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16047)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at …
Run Code Online (Sandbox Code Playgroud)

java android

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

应用启动画面给我错误您需要在此活动中使用 Theme.AppCompat 主题(或后代)

在 23 中,我们默认定义了这些样式,现在我必须以全屏启动启动画面

vlue/样式文件

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Run Code Online (Sandbox Code Playgroud)

v21样式文件:

 <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

显现:

 android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".User_MainInterface"
            android:label="@string/title_activity_user__main_interface"
            android:theme="@style/AppTheme.AppBarOverlay"></activity>
Run Code Online (Sandbox Code Playgroud)

请帮我快速解决这个问题

android android-studio

18
推荐指数
3
解决办法
6268
查看次数

长按时突出显示自定义列表视图项

我创建了listview一个ImageView左侧和TextView右侧的自定义.并Listview使用actionbar上下文菜单实现多选.

问题是,当我长时间点击某个项目时,它没有突出显示.

这是我listview在我的设置中的方式ListFragment

PasswordsFragment.java

package mohd.itcs.safewallet;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AbsListView.MultiChoiceModeListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;

public class PasswordsFragment extends ListFragment {

private String titles[] = { "item1", "item2", "item3" };

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setListAdapter(new CustomPasswordsList(getActivity(), titles));

}

@Override
public void onActivityCreated(Bundle savedInstanceState) {

    super.onActivityCreated(savedInstanceState);

    /*
     * Setup Multiple Selection Mode
     */
    getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); …
Run Code Online (Sandbox Code Playgroud)

android listview android-listview

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

在Google Maps Android API v2中使用文本标记标记

我已经想出了这篇文章,但它适用于已弃用的Google Maps API

http://tech.truliablog.com/2012/02/23/custom-map-markers-for-android-google-maps/

在新的API中,我找不到一个简单的方法来做到这一点.事实上,我根本做不到.

基本上我想在地图上将TextViews作为标记使用9Patch drawable作为文本的背景.Trulia仍然在他们当前的应用程序中使用新的API v2.你可以在这里查看

Trulia当前的应用程序

我怎样才能做到这一点?

android google-maps google-maps-markers google-maps-android-api-2

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

在Android中创建触摸绘制的喷雾效果

我的应用程序要求我在用户触摸屏幕时创建类似喷雾的效果.用户可以选择颜色.我需要用用户选择的颜色来创建类似喷雾的效果.我不确定它是否可能.如果可能,请建议我链接或指南.

java android

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

滚动时如何将数据从服务器加载到listview?

我有一个列表视图,显示图像和文本.我希望一次显示8个listview行,从服务器下载数据.当用户滚动列表视图时,我需要从服务器下载更多数据并在列表视图中显示这些项目.我使用AsyncTask从服务器下载数据.

@Override
    protected Void doInBackground(Void... params) {
        getData();// get data first time. 8 data items.
        return null;
    }

   @Override
   protected void onPostExecute(Void result) {

        super.onPostExecute(result);
        pd.dismiss();
        lv= (ListView) findViewById(R.id.lvn);
        yt = new YouTubeAdapter(Youtube.this,msg,title,thumb);
        lv.setAdapter(yt);
        lv.setOnScrollListener(new EndLessScroll());

    }
Run Code Online (Sandbox Code Playgroud)

获取数据代码

   public void getData()
{
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    HttpGet request = new HttpGet("http://gdata.youtube.com/feeds/api/users/mbbangalore/uploads?v=2&alt=jsonc");     
    try
    {
    HttpResponse response = httpclient.execute(request);
    HttpEntity resEntity = response.getEntity();
    String _response=EntityUtils.toString(resEntity); // content will be consume only once

    JSONObject json = new JSONObject(_response);

    jsonArray = …
Run Code Online (Sandbox Code Playgroud)

android listview

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