小编Ren*_*ith的帖子

使用match_parent属性获取WIDTH视图?

我有一个imageViewlayout_width="match_parent".

在我的适配器上getView(),我想得到它的实际宽度,imageView但不知道如何.

我尝试过使用imageView.getWidth(),但这会返回0.

android view width

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

如何在列表视图中显示所有朋友的姓名

我想通过我的应用程序登录到Facebook后显示好友列表ListView.但我的代码不起作用.我也使用了像friendsArrayAdapter这样的类.我使用了以下代码

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.friendlist_screen);
    facebook = new Facebook(APP_ID);
    mAsyncRunner = new AsyncFacebookRunner(facebook);

    lv = (ListView) findViewById(R.id.friendsList);
    friendsArrayAdapter = new FriendsArrayAdapter(this, R.layout.rowlayout, friends);
    lv.setAdapter(friendsArrayAdapter);
}
Run Code Online (Sandbox Code Playgroud)

FriendsRequestListener.class

public class FriendsRequestListener implements com.facebook.android.AsyncFacebookRunner.RequestListener {

    public void onComplete(final String response, Object state) {
        mSpinner.dismiss();
        try {
            // process the response here: executed in background thread
            Log.d("Facebook-Example-Friends Request", "response.length(): " + response.length());
            Log.d("Facebook-Example-Friends Request", "Response: " + response);

            final JSONObject json = new JSONObject(response); …
Run Code Online (Sandbox Code Playgroud)

android android-facebook

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

如何从facebook sdk获得用户生日?

如何获得用户生日user.getBirthday()

Session.openActiveSession(this, true, new Session.StatusCallback() {
      // callback when session changes state
      @Override
      public void call(Session session, SessionState state, Exception exception) {
        if (session.isOpened()) {

          // make request to the /me API
          Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

            // callback after Graph API response with user object
            @Override
            public void onCompleted(GraphUser user, Response response) {
              if (user != null) {
                TextView welcome = (TextView) findViewById(R.id.textView1);
                welcome.setText("Hello " + user.getBirthday() + "!");
                Log.d("user_birthday","user_birthday:"+user.getBirthday());//user.getBirthday()  this value always is null?
              }
            }
          }); …
Run Code Online (Sandbox Code Playgroud)

sdk android facebook

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

从PackageManager获取本地化标签名称的方法

PackageManager.getApplicationLabel(ApplicationInfo)用来获取应用程序名称.但是,此名称可能会根据设备区域设置配置和应用程序资源字符串而更改.

所以我想知道是否有任何方便的方法来获取指定的本地化标签(如果不存在则返回null)?如PackageManager.getApplicationLabel(ApplicationInfo info, Locale prefereLocale)

android android-package-managers

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

Android SDK无法获取URL

Android SDK无法获取URL,这是SDK Manager日志消息.

Fetching https://dl-ssl.google.com/android/repository/addons_list-2.xml
Fetched Add-ons List successfully
Fetching URL: https://dl-ssl.google.com/android/repository/repository-7.xml
Done loading packages.
Fetching https://dl-ssl.google.com/android/repository/addons_list-2.xml
Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-2.xml, reason: Cannot assign requested address: connect
Fetched Add-ons List successfully
Fetching URL: https://dl-ssl.google.com/android/repository/repository-7.xml
Failed to fetch URL https://dl-ssl.google.com/android/repository/repository-7.xml, reason: Bind Cannot assign requested address: connect
Done loading packages.
Run Code Online (Sandbox Code Playgroud)

我正在使用windows 864位系统.

sdk android windows-8

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

在字符串中添加换行符

如何在每个文本后创建一个新行?

这是代码.

String body = txtName.getText().toString() + txtLatitude.getText().toString() + txtLongitude.getText().toString();
ii.putExtra(android.content.Intent.EXTRA_TEXT, body);
Run Code Online (Sandbox Code Playgroud)

我试图只使用,\n但它给了我错误.请帮我.

android newline textview

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

LinearLayout显示项目从下到上

我有一个LinearLayout.我在运行时添加项目.但所有项目都从TOP到BOTTOM显示.现在我正在尝试将项目BOTTOM显示为TOP.

我的意思是.我想从BOTTOM到TOP开始设置线性布局的项目.

这是我的线性布局: -

 messagesContainer = (ViewGroup) findViewById(R.id.messagesContainer);
    scrollContainer = (ScrollView) findViewById(R.id.scrollContainer);

   LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
   LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);


    if (!leftSide) {
        bgRes = R.drawable.right_message_bg;
        params.gravity = Gravity.RIGHT;
        params.leftMargin=30;
    }
    else
    {
        params.gravity = Gravity.LEFT;
        params.rightMargin=30;
    }

    textView.setLayoutParams(params);

    textView.setBackgroundResource(bgRes);

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            messagesContainer.addView(textView,messagesContainer.getChildCount());

            //messagesContainer.bringChildToFront(textView);

            // Scroll to bottom
            if (scrollContainer.getChildAt(0) != null) {
                scrollContainer.scrollTo(scrollContainer.getScrollX(), scrollContainer.getChildAt(0).getHeight());
            }
            scrollContainer.fullScroll(View.FOCUS_DOWN);
            scrollContainer.pageScroll(View.FOCUS_DOWN);
        }
    });
Run Code Online (Sandbox Code Playgroud)

请帮我.

android android-linearlayout

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

无法导入google-play-services_lib,因为项目名称正在使用中

我已经完成了一个应用程序,它显示了一个参考本教程的Google地图

http://www.vogella.com/articles/AndroidGoogleMaps/article.html

该应用程序运行良好,它显示了一个谷歌地图,如教程中所示.但是现在,当我打开项目时,它会显示与导入com.google包有关的几个错误.我已经添加了google_play_services_lib.但是现在,应用程序中没有显示.当我再次尝试导入google_play_services_lib时,会出现此错误,

"无法导入google-play-services_lib,因为项目名称正在使用中"

问题是什么?请帮我.

android google-maps

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

Android调用getview

我对android中的方法getview有疑问.我的getview方法(在课堂上QuestionsListAdapter):

public View getView(int position, View convertView, ViewGroup parent){
    QuestionView qv;
    if (convertView == null) {
        qv = new QuestionView (nContext, nQuestion[position], nDetail[position], nExpanded[position]);
    } else {
        qv = (QuestionView)convertView;
        qv.setName(nQuestion[position]);
        qv.setDetail(nDetail[position]);
        qv.setExpanded(nExpanded[position]);
    }        
    return qv;
}
Run Code Online (Sandbox Code Playgroud)

但是我如何调用该方法?如果我没有旧视图而父母没有LayoutParams.FILL_PARENT

我的onCreate:

@Override
public void onCreate(Bundle savedInstanceState){
   super.onCreate(savedInstanceState);

   // Use our own list adapter
   setListAdapter(new QuestionsListAdapter(this));
}
Run Code Online (Sandbox Code Playgroud)

那么我该如何调用getView方法,因为如果我运行代码它就不会绘制.像这样的东西?

QuestionsListAdapter.getView( 0,  convertView,  parent);
Run Code Online (Sandbox Code Playgroud)

android view textview method-call listadapter

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

如果没有调用setcontentview(),为什么findViewById()返回null?

我是android的新手.

这是我的xml文件 -

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" 
    android:id="@+id/linearlayout"
    android:orientation="vertical">

    <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="@string/hello_world"
     android:id="@+id/textview" />

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

和非常基本的代码 -

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

    View view=getLayoutInflater().inflate(R.layout.activity_main,null);

            //setContentView(view);

            LinearLayout ly = (LinearLayout)findViewById(R.id.linearlayout);

            Log.i("System.out ","linear layout = " + view);

            Log.i("System.out ","linear layout = " + ly);
    }
Run Code Online (Sandbox Code Playgroud)

输出:

05-10 11:44:15.996: I/System.out(6494): linear layout = android.widget.LinearLayout@41e34db8
05-10 11:44:15.996: I/System.out(6494): linear layout = null
Run Code Online (Sandbox Code Playgroud)

findViewById()正在返回null?为什么?

如果我取消注释setContentView(view)并再次运行..

输出:

05-10 11:50:12.781: I/System.out(7791): linear layout = android.widget.LinearLayout@41e0d6c8
05-10 11:50:12.781: I/System.out(7791): …
Run Code Online (Sandbox Code Playgroud)

null android inflate findviewbyid

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