2013. 5. 2. 19:28

ScrollView 안에 EditText 의 scroll 이 먹지 않는 문제 

After struggling with that problem for quite some time, I've found a solution that seems to work without being too ugly. First, make sure that whatever ViewGroup (directly) contains your EditText has DescendantFocusability set to "Before Descendants," Focusable set to "true" and FocusableInTouchMode set to "true." This will not be the ScrollView itself, but the layout inside where you have your various views. Next add an onTouchListener to your ScrollView that removes focus from the EditText whenever it is touched, like so:

ScrollView scroll = (ScrollView)findViewById(R.id.scrollView1);
scroll.setOnTouchListener(new OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (myEditText.hasFocus()) {
            myEditText.clearFocus();
        }
        return false;
    }
});

Tell me if that doesn't fix it. What should happen is that the Layout gets focus instead of the EditText, so no scrolling should happen.


이외에 하나더있음. 정리중...

'Android > 개발팁' 카테고리의 다른 글

Android log 작성법  (0) 2013.05.22
패키지 네이밍 !  (0) 2013.05.07
EditText 테두리 없애기  (0) 2013.02.26
Android click 과 longclick 구분 방법  (0) 2013.01.08
3G, WIFI 연결 상태 확인하기.  (0) 2012.12.07
Posted by hoonihoon
2013. 2. 26. 17:41

 android:background="@null"

Posted by hoonihoon
2013. 1. 8. 14:17

setOnItemLongClickListener(new OnItemLongClickListener() {


@Override

public boolean onItemLongClick(AdapterView<?> adapter, View view,

int position, long id) {

return true;

}

});


return 값을 true 로 하면 된다.

Posted by hoonihoon
2012. 12. 7. 16:55

예전에 네이버 API 를 이용해 스터디용 영화검색 app 만들었는데, 망연결 상태도 확인안하고 무조건 server에 요청해서

서버에 응답이 없음이라는 결과를 얻기까지 시간이 많이 걸렸었다.

이제는 요청전에 네트워크 상태를 확인해보자.

ConnectivityManager connectManager = (ConnectivityManager) getSystemService(this.CONNECTIVITY_SERVICE);

boolean isMobileOn = connectManager .getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();

boolean isWifiOn = connectManager .getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();

 

AndroidManifest.xml 에 다음과 같이 추가한다.

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

 

실시간으로 받고 싶다면 ?

broadcast 를 만들고 intenr-filter에 해당 코드를 넣어준다.

<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>

 

* 중요한 것은 네트워크 상태를 언제 확인하느냐가 중요하다. server 와 통신이 잦은 어플이라면

요청시에 network check 를 해서 보낼 것인지,  broadcast 로 받아 flag 값을 값을 통해 확인 할 것인지는

server 와 통신하는 양의 차이일 것이다.


 

 

Posted by hoonihoon
2012. 11. 28. 16:58

 

@ 스크린 사이즈 구하기

DisplayMetricsdm = new DisplayMetrics();

getWindowManager().getDefeaultDisplay().getMetrics(dm);

dm.widthPixels;

dm.heightPixels;

 

@ 레이아웃 사이즈 구하기

LinearLayout animLayout;

animLayout = (LinearLayout) findViewById(R.id.anim_layout);

int w = animLayout.getMeasuredWidth();

int h = animLayout.getMeasuredHeight();

Posted by hoonihoon
2012. 11. 15. 16:54

퍼온 곳 :http://javaexpert.tistory.com/trackback/457

 

Hello Friends,

There are two or many more header listview in android. So Today we are discussed about the two header of android.

And See Also Simple Listview Display In Android Device.

So This are the all java and xml file given below. and this are the very useful projects.

main.xml


<?xml version="1.0" encoding="utf-8"?>
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="true"
/>

header.xml

<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" android:scrollbars="none"
style="?android:attr/listSeparatorTextViewStyle" />

Now The java File code Given below.

SectionedAdapter .java

package com.android.listview;

import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.BaseAdapter;
import java.util.ArrayList;
import java.util.List;

abstract public class SectionedAdapter extends BaseAdapter {
abstract protected View getHeaderView(String caption, int index,
View convertView, ViewGroup parent);

private List
sections = new ArrayList
();
private static int TYPE_SECTION_HEADER = 1;

public SectionedAdapter() {
super();
}

public void addSection(String caption, Adapter adapter) {
sections.add(new Section(caption, adapter));
}

public Object getItem(int position) {
for (Section section : this.sections) {
if (position == 0) {
return (section);
}

int size = section.adapter.getCount() + 1;

if (position <>
return (section.adapter.getItem(position - 1));
}

position -= size;
}

return (null);
}

public int getCount() {
int total = 0;

for (Section section : this.sections) {
total += section.adapter.getCount() + 1; // add one for header
}

return (total);
}

public int getViewTypeCount() {
int total = 1; // one for the header, plus those from sections

for (Section section : this.sections) {
total += section.adapter.getViewTypeCount();
}

return (total);
}

public int getItemViewType(int position) {
int typeOffset = TYPE_SECTION_HEADER + 1; // start counting from here

for (Section section : this.sections) {
if (position == 0) {
return (TYPE_SECTION_HEADER);
}

int size = section.adapter.getCount() + 1;

if (position <>
return (typeOffset + section.adapter
.getItemViewType(position - 1));
}

position -= size;
typeOffset += section.adapter.getViewTypeCount();
}

return (-1);
}

public boolean areAllItemsSelectable() {
return (false);
}

public boolean isEnabled(int position) {
return (getItemViewType(position) != TYPE_SECTION_HEADER);
}

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

for (Section section : this.sections) {
if (position == 0) {
return (getHeaderView(section.caption, sectionIndex,
convertView, parent));
}

int size = section.adapter.getCount() + 1;

if (position <>
return (section.adapter.getView(position - 1, convertView,
parent));
}

position -= size;
sectionIndex++;
}

return (null);
}

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

class Section {
String caption;
Adapter adapter;

Section(String caption, Adapter adapter) {
this.caption = caption;
this.adapter = adapter;
}
}
}

Selection.java


package com.commonsware.android.listview;

import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class SectionedDemo extends ListActivity {
private static String[] items = { "US", "UK", "CANADA", "JAPAN", "SINGAPORE",
"INDIA", "CHINA" };

private static String[] Sect = { "GOOGLE", "FACEBOOK","DELL" };

private static String[] Doc = { "FRONT", "TOP","BACK" };

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

adapter.addSection("step 1", new ArrayAdapter(this,
android.R.layout.simple_list_item_1, items));

adapter.addSection("Step 2", new ArrayAdapter(this,
android.R.layout.simple_list_item_1, Sect));

adapter.addSection("Step 3", new ArrayAdapter(this,
android.R.layout.simple_list_item_1, Doc));

setListAdapter(adapter);
}

SectionedAdapter adapter = new SectionedAdapter() {
protected View getHeaderView(String caption, int index,
View convertView, ViewGroup parent) {
TextView result = (TextView) convertView;

if (convertView == null) {
result = (TextView) getLayoutInflater().inflate(
R.layout.header, null);
}

result.setText(caption);

return (result);
}
};
}


And Now The output given below.






Posted by hoonihoon
2012. 11. 14. 14:35

android:singleLine="true" : 한줄에 표시
android:ellipsize="none" : 한줄이 넘을 경우 '...' 표시하지 않음
android:ellipsize="start" : 한줄이 넘을 경우 '...' 을 문장 앞에 표시
android:ellipsize="middle" : 한줄이 넘을 경우 '...' 을 문장 가운데 표시
android:ellipsize="end" : 한줄이 넘을 경우 '...' 을 문장 끝에 표시

android:ellipsize="marquee" : text가 좌에서 우로 이동하는 효과

android:singleLine="true"
android:focusable="true" <-- 3개의 속성을 함께 지정해야함

그리고 소스에서 setSelected(true); 를 설정해야 함

'Android > 개발팁' 카테고리의 다른 글

Android 스크린 사이즈와 layout size 구하기  (0) 2012.11.28
ListView 에 제목줄 을 달아 보자  (0) 2012.11.15
EditText 글자 짤림 현상  (0) 2012.08.27
한글 처리 문제  (0) 2012.08.27
SoftKeyboard 생성, 삭제  (0) 2012.08.27
Posted by hoonihoon
2012. 8. 27. 09:44

EditText안에 파일 왼쪽위로 정렬

android:gravity="top|left"     

 

공간두기   ( j , q 의 짤림현상이 발생했을때

android:lineSpacingExtra="2sp"

 

'Android > 개발팁' 카테고리의 다른 글

ListView 에 제목줄 을 달아 보자  (0) 2012.11.15
Text 관련 처리 (한줄 넘어가는 현상)  (0) 2012.11.14
한글 처리 문제  (0) 2012.08.27
SoftKeyboard 생성, 삭제  (0) 2012.08.27
타이틀바 없애기  (0) 2012.08.27
Posted by hoonihoon