小编use*_*637的帖子

使用Android应用程序的自定义适配器动态添加项目到列表视图

所以,现在我有一个自定义适配器类,它接收一个Locations数组并将它们添加到ListView.这很好,花花公子,但我希望在初始化后将Locations添加到此listview.例如,有人可以"添加位置",它会将其添加到此ListView.这是我的主要活动:

package com.example.listviewtest;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class MainActivity extends Activity {

private ListView listView1;

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

    Location location_data[] = new Location[]
    {
        new Location(R.drawable.ic_launcher, "Location 1", "Fruit!", "2 miles", "8-4 mon-fri\nclosed sun"),
        new Location(R.drawable.ic_launcher, "Location 2", "Veggies!", "2 miles", "8-5"),
        new Location(R.drawable.ic_launcher, "Location 3", "Plants!", "2 miles", "8-5"),
        new Location(R.drawable.ic_launcher, "Location 4", "Flowers!", "2 miles", "8-5"),
        new Location(R.drawable.ic_launcher, "Location 5", "Baked Goods!", "2 miles", "8-5")
    };

   LocationAdapter adapter …
Run Code Online (Sandbox Code Playgroud)

java android listview android-layout android-listview

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

java.lang.NoClassDefFoundError:android.support.v4.content.LocalBroadcastManager facebook android app

我知道这个问题已被提出,我已经尝试过使用其他许多帖子来帮助我完成这个但是没有一个有效.我正在通过此链接安装Facebook登录到Android应用程序:https://developers.facebook.com/docs/android/getting-started.我已经导入了Facebook SDK,它适用于示例应用程序,所以我知道没关系.我的libs文件夹中没有任何JAR.在属性> Android库中,我添加了appcompat_v7和FacebookSDK.在Built Path> Order and Export中,我检查了Android Dependencies和Android Private Libraries.

错误

java.lang.NoClassDefFoundError: android.support.v4.content.LocalBroadcastManager

发生在这行代码上:

Session.openActiveSession(this, true, new Session.StatusCallback() {

有关为什么会发生这种情况的任何想法?我一整天都在弄乱我的房产而且无法让它运转起来.代码就在FB开发者网站上,所以我确定它很好.谢谢.

07-23 16:19:18.506: W/dalvikvm(22318): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
07-23 16:19:18.506: W/dalvikvm(22318): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
07-23 16:19:18.506: W/dalvikvm(22318): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
07-23 16:19:18.506: W/dalvikvm(22318): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
07-23 16:19:18.506: I/dalvikvm(22318): Could not find method android.support.v4.content.LocalBroadcastManager.getInstance, …
Run Code Online (Sandbox Code Playgroud)

java android facebook properties

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

单击"信息窗口Google Maps V2的监听器"

我有一个简单的"地方"课程:

public class Plac{
    String name;
    int id;
    LatLng latlng;

    public Product(String name, int id, LatLng latlng) {
        this.name = name;
        this.id= id;
        this.latlng = latlng;
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在向这样的ArrayList添加"Places":( 注意名称不是唯一的)

ArrayList<Place> places = new ArrayList<Place>();
places.add(new Place("McDonald's", 1));
places.add(new Place("McDonald's", 2));
places.add(new Place("McDonald's", 3));
Run Code Online (Sandbox Code Playgroud)

我正在为我的Google地图添加标记,如下所示:

for(Place place : places)
map.addMarker(new MarkerOptions().position(place.latlng).title(place.name);
Run Code Online (Sandbox Code Playgroud)

我想知道如何为每个添加到地图的标记添加一个监听器.我试过用

map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {

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

但是,我唯一可以做的就是得到标记的标题,这不是唯一的,所以我无法真正找到点击哪个EXACT"Place"对象.有任何想法吗?谢谢

java android google-maps google-maps-markers

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

如何根据Android中当前位置的距离对地理点进行排序

我有一个"Place"对象,每个对象都有一个LatLng坐标:

import com.google.android.gms.maps.model.LatLng;

public class Place{
    public String name;
    public LatLng latlng;

    public Restaurant(String name, LatLng latlng) {
        this.name = name;
        this.latlng = latlng;
    }
}
Run Code Online (Sandbox Code Playgroud)

我有这些地方的ArrayList,如下所示:

    ArrayList<Place> places = new ArrayList<Place>();
    places.add("Place 1", LatLng(90.0,90.0));
    places.add("Place 2", LatLng(93.0,93.0));
    places.add("Place 3", LatLng(83.0,92.0));
    places.add("Place 4", LatLng(93.0,91.0));
Run Code Online (Sandbox Code Playgroud)

我有"我的"LatLng:

    LatLng myLocation = new LatLng(10.0,10.0);
Run Code Online (Sandbox Code Playgroud)

如何根据离我最近的方式对这些物体进行排序?谢谢您的帮助

android geolocation latitude-longitude

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

Google Map v2 缩放以适应所有标记和折线

因此,我在我的 Android 应用程序上的 Google 地图上显示了从 A 点到 B 点的路线。这一切都很好。我现在正在做的是通过执行以下操作来缩放以适应地图上的两个标记:

LatLngBounds.Builder builder = new LatLngBounds.Builder();

for (LatLng marker : markerPoints) {
    builder.include(marker);
}

LatLngBounds bounds = builder.build();
int padding = 20; // offset from edges of the map in pixels
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds,
        padding);
map.moveCamera(cu);
map.animateCamera(cu);
Run Code Online (Sandbox Code Playgroud)

问题是这不包括折线,所以如果路线超出屏幕,它会切断折线,如下所示:

在此处输入图片说明

关于如何缩放以适应折线的任何想法?谢谢!

java android google-maps

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

活动完成后停止 Handler Runnable

我有一种方法可以让 TextView 充当“正在加载...”指示器。

我正在用一个 Runnable 来做这件事,它每 0.5 秒更新一次 TextView。这是我的功能:

public void displayFlash() {
    animate = true;
    Handler handler = new Handler();
    Runnable runnable = new Runnable() {
        public void run() {
            while(animate) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                handler.post(new Runnable() {
                    public void run() {
                        System.out.println("Running");
                        numFrames++;
                        switch (numFrames % 3) {
                        case 0:
                            loading.setText("Loading.");
                            break;
                        case 1:
                            loading.setText("Loading..");
                            break;
                        case 2:
                            loading.setText("Loading...");
                            break;

                        }
                    }
                });
            }
    }
    };
    new Thread(runnable).start();
}
Run Code Online (Sandbox Code Playgroud)

问题是,在此活动完成(并销毁)后,线程继续运行。我System.out.println("running"); …

java multithreading android runnable

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

如何从Android应用程序中的异步任务返回位图

好吧,所以这段代码就在Android开发者网站上,该网站设置ImageViewBitmap:

class BitmapWorkerTask extends AsyncTask<Integer, Void, Bitmap> {
private final WeakReference<ImageView> imageViewReference;
private int data = 0;

public BitmapWorkerTask(ImageView imageView) {
    // Use a WeakReference to ensure the ImageView can be garbage collected
    imageViewReference = new WeakReference<ImageView>(imageView);
}

// Decode image in background.
@Override
protected Bitmap doInBackground(Integer... params) {
    data = params[0];
    return decodeSampledBitmapFromResource(getResources(), data, 100, 100));
}

// Once complete, see if ImageView is still around and set bitmap.
@Override
protected void onPostExecute(Bitmap bitmap) { …
Run Code Online (Sandbox Code Playgroud)

java android bitmap imageview android-asynctask

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

java.lang.UnsupportedOperationException:无法转换为color:type = 0x2 on setErrorEnabled for InputTextLayout

我有一个TextInputLayout:

<android.support.design.widget.TextInputLayout
    android:id="@+id/passwordLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColorHint="#FFF"
    android:theme="@style/TextInputLayoutWhite"
    app:errorTextAppearance="@style/ErrorText"
    app:hintTextAppearance="@style/TextInputLayoutWhite">

    <EditText
        android:id="@+id/passwordInput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Password"
        android:imeOptions="actionGo"
        android:singleLine="true"
        android:textColor="#FFF"
        app:theme="@style/WhiteEditText">

    </EditText>
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

我在我的Activity中设置了一个错误,如下所示:

passwordLayout.setErrorEnabled(true);

这就是投掷 java.lang.UnsupportedOperationException: Can't convert to color: type=0x2

如果我app:errorEnabled在我的xml布局中设置TextInputLayout,错误文本会显示,但我不希望它一直"启用",因为它为textview增加了额外的空间,直到我需要显示错误时才需要.

任何想法为什么这是扔java.lang.UnsupportedOperationException?这是完整的堆栈跟踪:

03-16 19:31:22.078 32577-32577/com.example.myapp W/ResourceType: Too many attribute references, stopped at: 0x01010099
03-16 19:31:22.078 32577-32577/com.example.myapp W/ResourceType: Too many attribute references, stopped at: 0x0101009a
03-16 19:31:22.078 32577-32577/com.example.myapp W/ResourceType: Too many attribute references, stopped at: 0x0101009b
03-16 19:31:22.078 32577-32577/com.example.myapp W/System.err: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
03-16 19:31:22.086 …
Run Code Online (Sandbox Code Playgroud)

java android android-textinputlayout

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

Android Google Maps v2可点击标记标题

我的应用上有谷歌地图.标记已经可以点击了,但是我正在寻找一种方法来使标题可点击以执行操作(比如去一个地方的"描述"页面).这就是我的意思

http://i.imgur.com/ndwOjx9.png?1

    public class MapFragment extends Fragment {

    private GoogleMap map;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_map, container,
                false);

        String myTag = getTag();
        ((PlacesAndMapActivity) getActivity()).setTabFragmentMap(myTag);


        map = ((SupportMapFragment) getFragmentManager().findFragmentById(
                R.id.map)).getMap();

        map.addMarker(new MarkerOptions().position(new LatLng(34.039407, -118.254763))
                .title("Restaurant 1"));

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

无论如何,我可以使标题可点击?谢谢

java maps android google-maps

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

如何在ListView中创建一行调整到Android应用程序中的内容

好的,现在我有一个具有设定高度的ListView.

好

但是当ListView的某一行内部的内容增长时...行没有

坏

正如您在第二张图片上看到的那样,内容在第一行被截断

当没有足够的空间时,有什么办法可以让单行展开吗?

活动代码:

public class MainActivity extends ActionBarActivity {

ArrayList<Location> arrayOfLocations;
LocationAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);

    // Construct the data source
    arrayOfLocations = new ArrayList<Location>();

    // Create the adapter to convert the array to views
    adapter = new LocationAdapter(this, arrayOfLocations);

    adapter.add(new Location(R.drawable.ic_launcher, "Fruit Stand",
            "We have the freshest fruit in the whole world!", "2 miles",
            "8-5 mon-sat\nclosed sun"));

    //getData();

    // Attach the adapter to a ListView
    ListView listView = (ListView) …
Run Code Online (Sandbox Code Playgroud)

java android listview android-listview

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