首页 > 编程技术 > android

夜神android模拟器设置代理的方法

发布时间:2016-9-20 19:55

夜神android模拟器如何设置代理呢?对于这个问题其实操作起来是非常的简单,下面小编来为各位详细介绍夜神android模拟器设置代理的方法,希望例子能够帮助到各位。
app开发测试的同学为了调试方便,通常会在电脑上装一些android模拟器,开多台进行测试。调试中通常要干的一件事就是抓取,那么想要抓包,我们必须要设置代理。

 

 

 

夜神android模拟机设置代理的方法:

 

 

 

1. 点击设置,然后进入到wifi连接选项。如图1:

 

 

 

夜深android模拟器设置代理步骤1

 

图1

 

 

 

2. 进入列表后,鼠标点击wifi位置,长按左键,会出现一个修改网络的弹窗,如下图:

 

 

 

夜深android模拟器设置代理步骤2

 

图2

 

 

 

3. 点击上图中的“修改网络”,会出现下图中的弹窗,勾选“显示高级选项”,接着一切都明了了,代理服务器主机名填写你电脑的ip就行了(window系统的话,用ipconfig查看),接着再填写端口。

 

 

 

夜深android模拟器设置代理步骤3

 

图3

 

 

 

4. 最后保存就ok了
centos下网站不能被局域网其他电脑访问的原因非常的简单,下面我们就一起来看看问题的解决办法,希望例子能够帮助到各位。
在centos下配置好apache服务器之后,用其他电脑访问我配好的网站,出现不能访问的情况,可能是已下原因导致的。

 

1. 先确保本机能够访问到,linux不像window那样能打开浏览器去访问,在linux中我们可以用telnet命令去看80端口有没有开启。具体命令为 telnet 192.168.115.129 80 ,如下图所示:

 

telnet 80端口

 

2. 再看apache是否有设置为让其他电脑访问,设置方法为打开apache配置文件,通常配置文件的路径为:/etc/httpd/conf/httpd.conf,找到“<Directory "/var/www/html">”,把里面相应的配置改为:

 

AllowOverride All

 

Order deny,allow

 

Allow from all

 

保存后,重启服务。

 

3. 如果上面两种都不行,那么试试下面两行命令,来开启对外访问80端口的权限:

 

iptables -I INPUT -p TCP --dport 80 -j ACCEPT

 

/etc/rc.d/init.d/iptables save

 

开启80对外访问权限

 

至此,应该大功告成了
Android报错有许多就像程序开发一样了,这里我们来看看activity_main cannot be resolved or is not a field错误的解决办法。

出现本错误的一般有两种情况

第一种情况:导包错误--检查import,找到这个:


删除之,再重新导入含有包名的R文件。

第二种情况:本情况应该更为多见,一般为布局文件中有错误,而无法生存R文件,可以检查一下:

Android报错activity_main cannot be resolved or is not a field


你会发现果真没有生成R文件,这时你需要解决的就是查找布局文件中的错误,改正错误,生成R文件之后,本错误就会消失啦!

下面我们来为各位整理一些关于ListView中的Item点击事件和子控件的冲突或者item点击没有反应问题解决办法了,具体的操作如下所示。

fragment中添加了button和checkbox这些控件,此时这些子控件会将焦点获取到,所以常常当点击item时变化的是子控件,item本身的点击没有响应。

这时候就可以使用descendantFocusability来解决啦,API描述如下:
android:descendantFocusability

该属性是当一个为view获取焦点时,定义viewGroup和其子控件两者之间的关系。

属性的值有三种:

beforeDescendants:viewgroup会优先其子类控件而获取到焦点

afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点

blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点

通常我们用到的是第三种,即在Item布局的根布局加上android:descendantFocusability=”blocksDescendants”的属性。

写这个demo顺便复习一下BaseAdapter

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class Audition1 extends Activity {

    private ListView listView;
a
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_audition1);
        initComponents();

    }

    private void initComponents() {
        listView = (ListView) findViewById(R.id.listView);
        listView.setAdapter(new MyAdapter(this));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                Toast.makeText(getApplicationContext(), "item", 300).show();

            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_audition1, menu);
        return true;
    }

    public final class ViewHolder {
        public TextView textView;
        public Button button;
        public ImageView imageView;
    }

    class MyAdapter extends BaseAdapter {

        private LayoutInflater mInflater;

        public MyAdapter(Context context) {
            this.mInflater = LayoutInflater.from(context);
        }

        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            if (convertView == null) {
                holder = new ViewHolder();

                convertView = mInflater.inflate(R.layout.item, null);
                holder.imageView = (ImageView) convertView
                        .findViewById(R.id.imageView);
                holder.textView = (TextView) convertView
                        .findViewById(R.id.textViewId);
                holder.button = (Button) convertView.findViewById(R.id.button);
                holder.textView.setText("shit");
                holder.button.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(
                                Audition1.this);
                        builder.setMessage("dialog");
                        builder.setTitle("title");
                        builder.create();
                        builder.show();
                    }
                });
                convertView.setTag(holder);
            } else {
                convertView.getTag();
            }

            return convertView;
        }

    }

}


<RelativeLayout 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" >

    <ListView
        android:id="@+id/listView"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:padding="@dimen/padding_medium"
        tools:context=".Audition1"
        android:dividerHeight="5dp"/>

</RelativeLayout>?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
 
    <TextView 
        android:id="@+id/textViewId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world"
        />
    <ImageView 
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        android:contentDescription="@string/app_name"
        />
 
    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="press"
        android:focusable="false"
        />
 
</LinearLayout>

原因是button强制获取了item的焦点,只要设置button的focusable为false即可。

findViewById方法在android开发中是获取页面控件的值了,有没有发现我们一个页面控件多了会反复研究写findViewById呢,下面我们一起来看它的简化方法。

Android中FindViewById()是一个非常常用的函数,位于android.app.Activity包中。该函数利用我们在XML文件中定义的View的id属性来获取相应的View对象。findViewById()属于API Level 1, 对应的android版本是android1.0, 由此,可以看出,该函数是android早期版本中就有的。顺便说一下, android目前市场上已商用的版本及其对应的API Level如下:

android 1.0API Level 1

android 1.1API Level 2

android 1.5API Level 3

android 1.6API Level 4

android 2.0API Level 5

android 2.0.1 API Level 6

android 2.1API Level 7

android 2.2API Level 8

1、参数错误:findViewById的参数是一个View的ID,如果在XML文件中没定义相应的ID,则程序会

善意的告诉你:XXX cannot be resulved。此时,补充定义就可以了。

2、未指定调用布局:findViewById()的调用与具体的布局有关,默认的是main.xml中的布局,函数前

 没有布局指示。不过,当我们在main.xml描述的布局中,添加其它布局时,利用该函数获

 取所添加布局中的View,则需在调用时,添加布局名,形式如下:

 addLayout.findViewById(), 如果不这么做,程序编译时有时不会报错,但运行时会

 提示遇到异常,并强制关闭应用。


3、命名冲突:这个错误可能不是很常见,不过,要是没有遇到过,猛的来这么一下,还真让人 有点懵。

 呵呵,本人就犯过这样的错误。解释下,这里的命名冲突是指当前工程中定义的类与

 android在Framework中提供的名字相同,这样的话,当前工程文件中,会优先使用本工

 程中的定义。当然,使用findViewById()函数时,发生这种错误必须满足以下几个条件:

 一是:需要在当前工程中利用ID(xml中定义)来查找对应的View对象;

 二是:查找的View类名恰好与本工程中已有的类定义相同

 三是:同名的两个类实例化后产生的对象类型不同,如:一个是View, 一个是Activity。

问题现象:

这样的代码熟悉吗?一个控件比较多的页面一直重复写这样的代码有没有很麻烦?

解决方法:


自定义一个方法:

public <T> T $(int viewID) {
 return (T) findViewById(viewID);
}

然后不管是什么类型的View,直接一个$方法搞定:


Android 反射简化findViewById .

官方例子里的小玩意。。。。。

一个注解:InjectView

 
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Use this annotation to mark the fields of your Activity as being injectable.
 * <p>
 * See the {@link Injector} class for more details of how this operates.
 */
@Target({ ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
public @interface InjectView {
    /**
     * The resource id of the View to find and inject.
     */
    public int value();
}

一个通过反射注解 并 实例化的功能类:


import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

import android.app.Activity;

/**
 * Very lightweight form of injection, inspired by RoboGuice, for injecting common ui elements.
 * <p>
 * Usage is very simple. In your Activity, define some fields as follows:
 *
 * <pre class="code">
 * @InjectView(R.id.fetch_button)
 * private Button mFetchButton;
 * @InjectView(R.id.submit_button)
 * private Button mSubmitButton;
 * @InjectView(R.id.main_view)
 * private TextView mTextView;
 * </pre>
 * <p>
 * Then, inside your Activity's onCreate() method, perform the injection like this:
 *
 * <pre class="code">
 * setContentView(R.layout.main_layout);
 * Injector.get(this).inject();
 * </pre>
 * <p>
 * See the {@link #inject()} method for full details of how it works. Note that the fields are
 * fetched and assigned at the time you call {@link #inject()}, consequently you should not do this
 * until after you've called the setContentView() method.
 */
public final class Injector {
    private final Activity mActivity;

    private Injector(Activity activity) {
        mActivity = activity;
    }

    /**
     * Gets an {@link Injector} capable of injecting fields for the given Activity.
     */
    public static Injector get(Activity activity) {
        return new Injector(activity);
    }

    /**
     * Injects all fields that are marked with the {@link InjectView} annotation.
     * <p>
     * For each field marked with the InjectView annotation, a call to
     * {@link Activity#findViewById(int)} will be made, passing in the resource id stored in the
     * value() method of the InjectView annotation as the int parameter, and the result of this call
     * will be assigned to the field.
     *
     * @throws IllegalStateException if injection fails, common causes being that you have used an
     *             invalid id value, or you haven't called setContentView() on your Activity.
     */
    public void inject() {
        for (Field field : mActivity.getClass().getDeclaredFields()) {
            for (Annotation annotation : field.getAnnotations()) {
                if (annotation.annotationType().equals(InjectView.class)) {
                    try {
                        Class<?> fieldType = field.getType();
                        int idValue = InjectView.class.cast(annotation).value();
                        field.setAccessible(true);
                        Object injectedValue = fieldType.cast(mActivity.findViewById(idValue));
                        if (injectedValue == null) {
                            throw new IllegalStateException("findViewById(" + idValue
                                    + ") gave null for " +
                                    field + ", can't inject");
                        }
                        field.set(mActivity, injectedValue);
                        field.setAccessible(false);
                    } catch (IllegalAccessException e) {
                        throw new IllegalStateException(e);
                    }
                }
            }
        }
    }
}

使用时类似:

 01.@InjectView(R.id.gygallery) 
02.private Gallery gallery; 
03.@InjectView(R.id.is_switcher) 
04.private ImageSwitcher imageSwitcher; 
 @InjectView(R.id.gygallery)
 private Gallery gallery;
 @InjectView(R.id.is_switcher)
 private ImageSwitcher imageSwitcher;

Activity>onCreate(){


Injector.get(this).inject();//init views

}

标签:[!--infotagslink--]

您可能感兴趣的文章: