小编The*_*mad的帖子

Android:spinner在Activity中工作但不在Fragment中工作

所以我能够Spinner在一个单独的工作Activity,但当我将代码转移到Fragment时,它显然不起作用.

我在这两行中遇到错误:

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.category_array, android.R.layout.simple_spinner_item);
ArrayAdapter<String> adapterItem = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, suggestedItems);
Run Code Online (Sandbox Code Playgroud)

我知道this需要改变背景.我已经尝试过使用getActivity(),但是效果不好.

需要一些见解!谢谢!

public class NominateFragment extends Fragment {

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

    View view = inflater.inflate(R.layout.fragment_nominate_page, container, false);

    //SPINNER
    Spinner spinner = (Spinner)getView().findViewById(R.id.category);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.category_array, android.R.layout.simple_spinner_item); // Create an ArrayAdapter using the string array and a default spinner layout
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Specify the layout to use when the …
Run Code Online (Sandbox Code Playgroud)

android fragment spinner

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

通过HTTP POST上传文件

我想使用将文件(特定于图像)上传到REST服务器HTTP POST.我已经导入/添加到构建路径httpmime-4.3.1.jarapache-mime4j-0.6.jar.我在堆栈跟踪中得到以下错误.

这有效吗? post.setHeader("enctype", "multipart/form-data");

HTTP POST代码

public void multiPartPost() throws ClientProtocolException, IOException {
    File image = new File(EXTERNALSTORAGE + "/Pictures/sample.jpg");
    FileBody fileBody = new FileBody(image);

    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(url);
    post.setHeader("enctype", "multipart/form-data");

    MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
    multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    multipartEntity.addPart("sampleImage", fileBody);
    post.setEntity(multipartEntity.build());

    HttpResponse response = client.execute(post);
    String responseBody = EntityUtils.toString(response.getEntity());
    Log.v("multiPartPost HTTP Response", responseBody);
}
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪

01-05 17:41:25.470: W/dalvikvm(6564): VFY: unable to resolve static field 1755 (DEFAULT_BINARY) in Lorg/apache/http/entity/ContentType;
01-05 …
Run Code Online (Sandbox Code Playgroud)

java rest http-post multipartentity

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

替换片段仍然在后台和可点击的事件响应

当我Fragment用另一个Fragment 替换a 时,替换的Fragment仍然在新Fragment后面,并且替换的Fragment中的可点击事件仍在工作.我看不到任何旧片段,但触摸事件仍然有效.

我甚至尝试在更换之前清理后备箱,但无济于事.

为什么会这样?

getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
getSupportFragmentManager().beginTransaction().replace(R.id.container, 
    MatchedFragment.newInstance(matchHistoryId, matchUserId, matchAvatar), "matchedFragment").commit();
Run Code Online (Sandbox Code Playgroud)

android android-fragments

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

为什么我得到getString错误?以及如何解决?

我正在测试FragmentPagerAdapter,之前我在一个类中完成了所有这些操作.一切正常,但是一旦我分离了SectionsPagerAdapter类,getString就不能在getPageTitle函数下工作了.

我知道getPageTitle是PagerAdapter类的一部分,但我想知道在这个类中包含该函数的最佳方法是什么.我需要延长课程吗?

SectionsPageAdapter类

import java.util.Locale;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

// A FragmentPagerAdapter that returns a fragment corresponding to one of the sections/tabs/pages. 
public class SectionsPagerAdapter extends FragmentPagerAdapter {

public SectionsPagerAdapter(FragmentManager fm) {
    super(fm);
}

@Override  
public Fragment getItem(int position) {  
    // getItem is called to instantiate the fragment for the given page.  
    // Return a DummySectionFragment (defined as a static inner class  
    // below) with the page number as its lone argument.  
    Fragment fragment = new …
Run Code Online (Sandbox Code Playgroud)

android getstring fragmentpageradapter

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

谷歌眼镜:在常规卡片中触摸打开菜单

如何在常规菜单中弹出菜单Card.我试过使用这段代码:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
     if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
          openOptionsMenu();
          return true;
     }
     return false;
}
Run Code Online (Sandbox Code Playgroud)

但它似乎没有用.此外,有把可能Live CardsActivity像我一样在这里.我相信我正在使用Static Cards,但最终我需要通过这些卡访问相机和视频功能.

活动

public class NewChecklistActivity extends Activity {

private GestureDetector mGestureDetector;
private List<Card> mCards;
private CardScrollView mCardScrollView;
StepCardScrollAdapter adapter;

Intent checklistIntent;
String allStepsJSONString;
ArrayList<String[]> allStepsArray;
ArrayList<String[]> checklistsArray;
ArrayList<String[]> stepsArray;
ArrayList<String[]> checklistSteps;

@SuppressWarnings("unchecked")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    checklistsArray = (ArrayList<String[]>) this.getIntent().getSerializableExtra("checklists");
    stepsArray = (ArrayList<String[]>) this.getIntent().getSerializableExtra("steps");

    createCards();
    mCardScrollView …
Run Code Online (Sandbox Code Playgroud)

android menu google-glass google-gdk

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

使用自定义ImageView类,获取NullPointerException

我使用自定义ImageView类使插入的图像适合屏幕的宽度,但保持纵横比.它似乎适用于我使用此自定义的所有其他地方ImageView,但不是这一页.无法弄明白/刮擦头.先感谢您!

  • 图像URL是从服务器调用的JSON接收的
  • 图像已加载 UrlImageViewHelper
  • 此ImageView与其他ImageView之间的唯一区别是它在加载时使用自定义动画

自定义ImageView类

public class AspectRatioImageView extends ImageView {

public AspectRatioImageView(Context context) {
    super(context);
}

public AspectRatioImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public AspectRatioImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int height = width * getDrawable().getIntrinsicHeight() / getDrawable().getIntrinsicWidth();
    setMeasuredDimension(width, height);
}

}
Run Code Online (Sandbox Code Playgroud)

包含ImageView的片段(剪掉所有不必要的代码)

public class MainFragment extends Fragment {

private AspectRatioImageView rateMember;

static MainFragment newInstance() …
Run Code Online (Sandbox Code Playgroud)

android nullpointerexception imageview

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

单击通知不打开应用/活动

我无法打开应用程序的通知.我按照Android文档上的说明进行操作,但无济于事.它创建通知没有问题,但点击它只是解散它.

请帮忙!提前致谢!

为什么点击通知没有打开应用程序?

Intent intent = new Intent(this, MainActivity.class);

    String type = "";
    if (extras.containsKey(KEY_TYPE)) type = extras.getString(KEY_TYPE);

    String text = "";

    if (type.equalsIgnoreCase(TYPE_MATCH_FOUND)) {
        // TODO: send intent with all variables, trigger matched fragment when user goes into app



        text = getResources().getString(R.string.msg_found_match);

        intent.putExtra(KEY_TYPE, TYPE_MATCH_FOUND);
    }
    else if (type.equalsIgnoreCase(TYPE_MESSAGE)) {
        // TODO: trigger chat fragment when user goes into app

        text = getResources().getString(R.string.msg_new_message_from);

        intent.putExtra(KEY_TYPE, TYPE_MESSAGE);
    }

    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);        

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher)
        .setContentTitle("LFDate")
        .setContentText(text)
        .setAutoCancel(true)
        .setLights(Color.parseColor("#0086dd"), …
Run Code Online (Sandbox Code Playgroud)

android push-notification android-intent android-pendingintent

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

带有 Nginx 的 SSL websockets 无法连接

有问题,有越来越Nginxproxy_pass使用WebSockets和SSL(WSS)。

NGINX 配置

map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
}

server {
    server_name site.io www.site.io;

    location / {
        proxy_pass         https://localhost:3000;
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   Host $http_host;
    }

    location /ws {
        proxy_pass         http://localhost:8989/graphql;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection "upgrade";
        proxy_set_header   Host $host;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/site.io/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/site.io/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by …
Run Code Online (Sandbox Code Playgroud)

ssl nginx websocket

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