小编wuf*_*foo的帖子

类扩展Android项目库中的应用程序?

我有我已经变成了一个Android项目库,以便在另一个类似的项目重新使用一些代码的项目(在Eclipse).因为我收到了错误,但我认为自己已经开枪了.

Unable to start activity ComponentInfo{com.test.scroller1/com.lib.scrolltest.ScrollTestActivity}: java.lang.ClassCastException: android.app.Application cannot be cast to com.lib.scrolltest.resAppVars
Run Code Online (Sandbox Code Playgroud)

com.lib.scrolltest是我的项目库,它实例化一个扩展Application(resAppVars)的类.在onCreate()方法中我调用:

mRav = (resAppVars) getApplicationContext ();
Run Code Online (Sandbox Code Playgroud)

这样,我可以使用mRav对象中的方法,否则在其他类中会有很多重复的代码(例如将查询传递给返回结果的ArrayList的泛型select语句).

这有什么问题?看来我在实现Application类的方式上遇到了限制.

android

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

Android和Twitter4j:使用Webview小部件处理OAuth?

我有一个有效的twitter4j实现,但用于授权应用程序的OAuth流程让Android Web浏览器在应用程序后面运行.我想尝试在已启动的活动中实现我自己的webview,这样我就可以完成()或至少在我的应用程序之后清理它.问题是,现在我必须弄清楚如何将authURL返回到我的主要活动.

返回authURL的最佳方法是什么?我已经子类化了一个webview小部件,我正在尝试一种方法来返回onPageFinished()中的authURL,但还没有.

private class myWebViewClient extends WebViewClient
{
    @Override
    public void onPageFinished (WebView view, String url)
    {
    Log.d (TAG, "onPageFinished");
       super.onPageFinished (view, url);

       if (url.contains (TwitterLibActivity.CALLBACK_URL) == true)
       {
        /*
        mRetIntent = new Intent();
        mRetIntent.putExtra ("verifed", url);
        setResult (RESULT_OK, mRetIntent);
        */
        Log.d (TAG, "have auth url:" + url);
        finish();
       }
    }


    @Override
    public boolean shouldOverrideUrlLoading (WebView view, String url)
    {
        Log.d (TAG, "myWebViewClient url:" + url);
       //return super.shouldOverrideUrlLoading (view, url);
        return (false);
    }
}
Run Code Online (Sandbox Code Playgroud)

twitter android oauth android-intent

6
推荐指数
2
解决办法
6182
查看次数

如何在单独的类中使用自定义ArrayAdapter?

我有一个扩展ArrayAdapter的内部类,以便自定义ListView.我想将这个内部类分解为一个单独的文件,以便其他类可以使用它,但在getLayoutInflater()时遇到一些问题.

基本上,我的getView()方法不知道getLayoutInflater()是什么,即使我正在扩展ArrayAdapter.任何人都知道如何正常工作?

谢谢!

public class myDynAdap extends ArrayAdapter<String>
{
    String [] list;


   public myDynAdap (Context context, int textViewResourceId, String [] objects)
   {
       super (context, textViewResourceId, objects);
       mCtx = context;
       list = objects;
   }

    @Override
    public View getView (int position, View convertView, ViewGroup parent)
    {
        View row = convertView;

        if (row == null)
        {

            LayoutInflater inflater = getLayoutInflater ();  // <--- "The method getLayoutInflater() is undefined for the type myDynAdap"
            row = inflater.inflate (R.layout.main_listitem, parent, false);
        }

        TextView tv1 = (TextView) …
Run Code Online (Sandbox Code Playgroud)

android android-arrayadapter

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

启动电子邮件意图后,Android键盘仍然可见

编辑:解决了.答案单独发布在下面

我正在启动内置的Intent.ACTION_SEND"选择器",以便用户可以选择如何从我的应用程序发送消息.它工作正常,但是如果我在启动的电子邮件程序中点击'Discard',它将返回到我的应用程序,屏幕键盘仍然可见.我试过用各种各样的imm.hideSoftInputFromWindow(...)关闭它,但无济于事.任何想法如何解决这一问题?

这就是我如何启动'选择器'并尝试在onActivityResult()中关闭键盘.请注意,tabHost是我的主应用程序(MainApp)中的静态成员,它包含用于创建tabSpecs的tabHost对象.

public class L_Secondary extends ListActivity implements myConst
{   
    @Override
   protected void onCreate (Bundle savedInstanceState)
   {
     super.onCreate (savedInstanceState);
     setContentView(R.layout.l_people_secondary);

     // instantiate the custom array adapter class and pass it some info to build a ListView with. 
     ListView lv = getListView ();
     lv.setOnItemClickListener (oicl);
     A_secondary da = new A_secondary (this, android.R.layout.simple_list_item_single_choice, mPiecesArray, mPartsArray);

     setListAdapter (da);
   }

   ...  


   // after launching the email client, the keyboard stays visible 
   // over the Listview. Currently the keyboard gets forced to …
Run Code Online (Sandbox Code Playgroud)

android android-intent

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

从Email Activity返回后,Android键盘仍然可见

我有一个在TabHost中运行的Activity(扩展Activity).我从用户操作启动Android电子邮件客户端.如果我点击电子邮件客户端中的"放弃"按钮,电子邮件客户端将退出,但屏幕上的键盘仍然可见.

我的应用程序上没有EditTexts,因此不确定为什么键盘会保持运行状态.我已经尝试了几次迭代,如何在完成活动后移除键盘?但是没有运气.有什么想法吗?

代码示例

package com.test.launchmail;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;

public class myEmail extends Activity
{
    private final String TAG = "** Email **";


    public static void send (Context ctx, String addy, String subject, String body)
    {
        // check to make sure the entry has a phone number
        try
        {
            // use the builtin chooser for users mail app
            Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.setType("text/plain");

            sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String [] {addy});
            sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, …
Run Code Online (Sandbox Code Playgroud)

android android-activity

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

如何在python中检测curses ALT +组合键

这里是python的新手,并使用curses导入.我想检测像ALT+ F和类似的关键组合.目前,我正在使用getch()接收密钥然后在curses窗口中打印它.值FALT+ 不会改变F.如何检测ALT组合键?

import curses

def Main(screen):
   foo = 0
   while foo == 0: 
      ch = screen.getch()
      screen.addstr (5, 5, str(ch), curses.A_REVERSE)
      screen.refresh()
      if ch == ord('q'):
         foo = 1

curses.wrapper(Main)
Run Code Online (Sandbox Code Playgroud)

python curses

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

静态方法与类扩展android.app.Application?

我有一个类,它在Android tabHost应用程序中扩展了Application.在App类中,我一直在放置方法和变量,否则我需要在每个类中重新创建.一种方法从DB读取并将结果存储在ArrayList(例如,名字,姓氏)中.我没有重新读取这个数据库并为每个需要信息的选项卡视图重新创建代码,而是将方法和ArrayList放在扩展Application(myAppClass)的类中.这样,通过mAC = (myAppClass) getApplicationContext()在onCreate()中的任何选项卡视图中设置,我可以引用myAppClass中的所有get ..()和set ..()方法.

我最初的计划是使用带有静态方法和变量的共享类,但我读了很多"不要那样做"的线程,因此决定使用Application路由.现在,我遇到了一种情况,我正在尝试在项目库中使用myAppClass,但是遇到错误android.app.Application cannot be cast to...如果我将myAppClass更改回静态方法/变量(并且不扩展应用程序)的东西工作,但这应该是是一个很大的禁忌.还有另一种方法吗?不确定Android是否通过引用传递了所有内容,但是我最好通过在方法/类之间来回传递巨大的(数千个对象/成员)ArrayLists来重新实现整个应用程序吗?

methods static android parameter-passing

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

D3JS缩放和转换性能

我有一些代码可以在D3中缩放和翻译地图,但性能非常糟糕.在缩放和平移时,刷新需要将近3秒钟.我认为地图会看起来更好,包括所有县的线路边界,但是在6MB +我怀疑这可能是瓶颈所在的地方.还有另一种方法我应该处理变换或者可能是一种优化地图数据的方法吗?D3真的不适合这个细节吗?D3很新. 在此输入图像描述

我正在使用此处的形状文件,使用QGIS从DBF转换为Geojson:https://www.census.gov/cgi-bin/geo/shapefiles2010/main

<!doctype html>
<html>

<head>
   <title>d3 map</title>
   <script src="http://d3js.org/d3.v3.min.js">
   </script>
</head>

<body>
   <script>
            var width = 800;
            var height = 600;

            var projection = d3.geo.mercator();
            var path = d3.geo.path().projection (projection);

            var canvas = d3.select ("body")
               .append ("svg")
               .attr ("width", width)
               .attr ("height", height)

            var zoomVar = d3.behavior.zoom()
               .translate(projection.translate())
               .scale(projection.scale())
               .scaleExtent([height, 60 * height])
               .on("zoom", onPostZoom);

            var hotbox = canvas.append("g").call(zoomVar);

            hotbox.append("rect")
               .attr("class", "background")
               .attr("width", width)
               .attr("fill", "white")
               .attr("height", height);     

            d3.json ("cali.geojson", function (data) 
            {
               hotbox.append("g")
                  .attr("id", "geometry") …
Run Code Online (Sandbox Code Playgroud)

transition d3.js

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

无法在Java.util.Calendar中设置月份

我在Android中有一个onClickListener,根据单击的+/-按钮更改Java.util.Calendar对象的月份.设置日历的代码如下.我似乎无法将月份设置为"10".世界上到底发生了什么?

Calendar c2 = Calendar.getInstance();
int newmonth = 9;
Log.d (TAG, "month before: "+ c2.get (Calendar.MONTH));
c2.set (Calendar.MONTH, newmonth);
Log.d (TAG, "month now: " + c2.get(Calendar.MONTH));
Run Code Online (Sandbox Code Playgroud)

一个月前:现在11个月:9

Calendar c2 = Calendar.getInstance();
int newmonth = 10;
Log.d (TAG, "month before: "+ c2.get (Calendar.MONTH));
c2.set (Calendar.MONTH, newmonth);
Log.d (TAG, "month now: " + c2.get(Calendar.MONTH));
Run Code Online (Sandbox Code Playgroud)

一个月前:现在11个月:11

java android calendar

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

如何在Eclipse AVD中使用Android手机挡板获取屏幕截图?

我有一个Android演示文稿,想要获得我的应用程序的一些截图.事实上,我想要在手机上运行应用程序的屏幕截图.

我可以使用相机并拍摄机器人手机+应用程序的照片,但在我看来,AVD 曾经在Nexus手机的图片中运行.只是想知道它是否是某个Eclipse配置选项?

谢谢!

eclipse android android-virtual-device

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

如何从Manifest获取android:versionName?

我想在我的应用程序Info(About)页面中显示AndroidManifest中的android:versionName.有办法吗?

android manifest

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

Java calendar.getTimeInMillis()返回额外的零?

我使用Java Calendar对象设置日期,然后以毫秒为单位获取时间,以确定两个不同时期的年表.在我去仔细检查返回值之前,这似乎是一个很棒的计划getTimeInMillis().
7月17日星期五00:00:00 CDT 2009返回1247806800 000,当我用Perl测试返回值时,似乎没有jive,这告诉我这个时代应该真的是1247806800(短3个零).

这些额外的零来自哪里?Java文档只是说getTimeInMillis()

以毫秒为单位返回此Calendar的时间值.

但不解释为什么会出现这种差异.

java calendar

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

ARC禁止自动释放?

新的ios并尝试从函数返回NSString.据我了解,我需要[NSString... alloc] init]为了返回创建字符串.此外,因为我打电话alloc,我想我必须自己自动释放该对象,但是我收到消息"ARC禁止'autorelease'的显式消息发送"所以..当我完成分配的NSString时,我怎么告诉ios ?

- (NSString *) generateUID
{
    char foo[32];
    // create buffer of all capital psuedo-random letters
    for (int i = 0; i < sizeof(foo); i++)
       foo[i] = (random() % 25) + 65; // 0-25 + CAPITAL_A

    NSString *uid = [[NSString alloc] initWithBytes:foo length:sizeof(foo) encoding:NSASCIIStringEncoding];
    NSLog (@"uid: %@", uid);
    return (uid);
}
Run Code Online (Sandbox Code Playgroud)

iphone nsstring ios

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