'전체 글'에 해당되는 글 132건

LED,가변저항,버튼 제어

Posted by PeEn
2020. 5. 5. 21:55 Programing/Arduino

 

 

//버튼 핀번호
int btnRed = 7;
int btnWhite = 6;

//LED 핀번호
int LEDRED = 2;
int LEDGREEN = 3;

//가변저항 셋팅
int ptMeter = A0;
int ptValue = 0;

//변수선언
int powerValue = 0;
int ledValue = 1;

void setup() {
  Serial.begin(9600);
  pinMode(btnRed,INPUT);
  pinMode(btnWhite,INPUT);
  pinMode(LEDRED,OUTPUT);
  pinMode(LEDGREEN,OUTPUT);
  


}

void loop() {
  int readVRed = digitalRead(btnRed); 
  int readVWhite = digitalRead(btnWhite);
  
  //가변저항 읽어오기
  ptValue = analogRead(ptMeter);
  //가변저항 적용
  ptValue = map(ptValue, 0, 1023, 0, 255);
  Serial.println(ptValue);
  
  if(readVRed==HIGH)
  {
    if(powerValue==0){
      powerValue = 1;
    }
    else if(powerValue==1){
      powerValue = 0;
      digitalWrite(LEDGREEN,LOW);
      digitalWrite(LEDRED,LOW);
    }
    
  }
  
  else if(powerValue==1){

    if(ledValue==1){
      digitalWrite(LEDGREEN,LOW);
      analogWrite(LEDRED, ptValue);

    }
    else if(ledValue==2){
      digitalWrite(LEDRED,LOW);
      analogWrite(LEDGREEN, ptValue);
    }
    if(readVWhite==HIGH){ 
      if(ledValue==1){
        ledValue=2;
      }
      else if(ledValue==2){
        ledValue=1;
      }
    }



  }
   
}

 

'Programing > Arduino' 카테고리의 다른 글

6FND, 초음파, 서보모터, Buzzer,매트릭스 키패드  (0) 2020.05.27
6digit FND  (0) 2020.05.25
LED 6개 순차 깜빡  (0) 2020.05.03

LED 6개 순차 깜빡

Posted by PeEn
2020. 5. 3. 20:53 Programing/Arduino
#define DELAY_TIME 100

void setup() {
  // put your setup code here, to run once:
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(2, HIGH);
  delay(DELAY_TIME);
  digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
  delay(DELAY_TIME);
  digitalWrite(3, LOW);
  digitalWrite(4, HIGH);
  delay(DELAY_TIME);
  digitalWrite(4, LOW);
  digitalWrite(5, HIGH);
  delay(DELAY_TIME);
  digitalWrite(5, LOW);
  digitalWrite(6, HIGH);
  delay(DELAY_TIME);
  digitalWrite(6, LOW);
}

'Programing > Arduino' 카테고리의 다른 글

6FND, 초음파, 서보모터, Buzzer,매트릭스 키패드  (0) 2020.05.27
6digit FND  (0) 2020.05.25
LED,가변저항,버튼 제어  (0) 2020.05.05

네트워크응용 Spring 업로드 웹사이트

Posted by PeEn
2020. 4. 20. 14:08 Programing/Web Programming

build

group 'io.goorm'
version '0.0.1'

buildscript{
    repositories{
        jcenter();
    }
    dependencies{
        classpath 'org.akhikhl.gretty:gretty:+'
    }
}

apply plugin: 'java'
apply plugin: 'org.akhikhl.gretty'
apply plugin: 'war'

sourceCompatibility = 1.8
targetCompatibility = 1.8

compileJava.options.encoding = 'UTF-8'


repositories {
    mavenCentral()
}

dependencies {
    providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
    testCompile group: 'junit', name: 'junit', version: '4.12'
    
}
def webappDir = "$rootDir/src/main/webapp"

gretty{
    httpPort = 8080
    contextPath = "/"
    servletContainer = "jetty9"
}

upload.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8"/>
        <title>FILE UPLOAD</title>
        
    </head>
    
    <body>
        <h1>
            FILE UPLOAD
        </h1>
        <form method="post" action="upload" enctype="multipart/form-data">
            업로드 할 파일 선택 : <input type="file" name="fileupload" id="fileupload"/>
            <input type="submit" value="파일전송"/>
        </form>
        
    </body>
</html>

UploadServlet.java

package iotnetwork;

import java.io.IOException;
import java.rmi.ServerException;

import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

@WebServlet(name="UploadServlet",urlPatterns = {"/upload"})
@MultipartConfig(
    fileSizeThreshold = 1024 * 1024 *2, //1MB
    maxFileSize = 1024 * 1024 * 10, //10MB/
    maxRequestSize = 1024 * 1024 * 30,
    location = "/workspace/IoTNetwork/src/main/webapp/upload"
)
public class UploadServlet extends HttpServlet{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse res)throws ServerException, IOException{
        res.setContentType("text/html");
        req.setCharacterEncoding("UTF-8");
        res.setCharacterEncoding("UTF-8");
        
        //multipart/form-data 는  HttpServletRequest의 part형태로 전달
        try{
            final Part filePart = req.getPart("fileupload");
        //파일 이름
            final String fileName = getFileName(filePart);
            System.out.println(fileName);
        
        }catch(Exception e){
            System.out.println("Error Upload");
        }
 
    }
    
    private String getFileName(final Part part){
        final String partHeader = part.getHeader("content-disposition");
        System.out.println(part.getSize()+", name:"+part.getName());
        System.out.println(partHeader);
        for(String content: part.getHeader("content-disposition").split(";")){
            if(content.trim().startsWith("filename")){
                return content.substring(content.indexOf("=")*1).trim().replace("\"","");
            
            }
        }
        return null;
    }
}

opencv 차량번호 인식 기초설치

Posted by PeEn
2020. 4. 1. 17:11 Programing/opencv
  1. 참조 : https://opentutorials.org/module/3811/25288
  2. 개발환경
    1. Windows 10
      1. tesseract-OCR 설치
        1. URL : https://github.com/UB-Mannheim/tesseract/wiki
        2. 다운로드 : tesseract-ocr-w64-setup-v5.0.0-alpha.20200223.exe
        3. 설치 : C:\Program Files\Tesseract-OCR
        4. 환경변수 PATH에 C:\Program Files\Tesseract-OCR 추가
      2. 한글 트레이닝 데이터 다운로드
        1. URL : https://github.com/tesseract-ocr/tessdata/blob/master/kor.traineddata
        2. 다운로드 : kor.traineddata
        3. 설치 : C:\Program Files\Tesseract-OCR\tessdata 에 복사
    2. Anaconda
      1. activate whan14 : 가상환경 whan14 사용
      2. pip install pillow : pillow 설치
      3. pip install pytesseract : pytesseract 설치
  3. 소스 코드 분석
    1. 모듈 추가

       
    2. 1.jpg 파일을 불러와 보여주기

       
    3. RGB -> GrayScale로 변환

       

Project2020

Posted by PeEn
2020. 3. 9. 20:38
보호되어 있는 글입니다.
내용을 보시려면 비밀번호를 입력하세요.

opencv_python 차번호판 숫자 인식

Posted by PeEn
2020. 1. 1. 02:27
보호되어 있는 글입니다.
내용을 보시려면 비밀번호를 입력하세요.

opencv_python 카메라 프레임 읽어오기, 캡처 저장하기

Posted by PeEn
2019. 12. 31. 22:43 Programing/opencv

opencv_python 카메라 프레임 읽어오기

# -*- coding: utf-8 -*-
import cv2

cap = cv2.VideoCapture(0)
if cap.isOpened():
    while True:
        ret, img = cap.read()
        if ret:
            cv2.imshow("camera",img) #프레임 이미지 표시
            if cv2.waitKey(1) != -1:
                break
        else:
            print("no fram")
            break
else:
    print("can't open camera")
cap.release()
cv2.destroyAllWindows()

opencv_python 캡처 저장하기

# -*- coding: utf-8 -*-
import cv2

cap = cv2.VideoCapture(-1)
if cap.isOpened():
    while True:
        ret, fram = cap.read()
        if ret:
            cv2.imshow("camera",fram) #프레임 이미지 표시
            if cv2.waitKey(1) != -1:
                cv2.imwrite("../photo.jpg",fram)
                break
        else:
            print("no fram")
            break
else:
    print("can't open camera")
cap.release()
cv2.destroyAllWindows()

 

opencv_python 이미지 불러오기, 저장

Posted by PeEn
2019. 12. 31. 21:42 Programing/opencv

opencv_python 이미지 불러오기

# -*- coding: utf-8 -*-
import cv2


img_file ="../pic/lena.jpg" #이미지 경로설정
img = cv2.imread(img_file) #이미지를 읽어 변수로 할당

if img is not None:
    cv2.imshow('IMG',img)    #이미지 화면에 표시
    cv2.waitKey()            #키입력까지 대기
    cv2.destroyAllWindows()  #창닫기
else:
    print("Don't found image file")

img_file ="이미지 경로, 읽기모드"
* 읽기모드를 쓰지 않으면 RGB모드로 읽어온다.

opencv_python 이미지 저장, 그레이 모드로 읽기

# -*- coding: utf-8 -*-
import cv2

img_file = "../pic/lena.jpg" #이미지 경로설정
save_img = "../pic/lena_gray.jpg" # 저장할 경로설정

img = cv2.imread(img_file, cv2.IMREAD_GRAYSCALE) #이미지를 그레이모드로 읽어 변수로 할당

if img is not None:
    cv2.imshow('IMG',img)           #이미지 화면에 표시
    cv2.imwrite(save_img,img)  		#이미지 저장
    cv2.waitKey()                   #키입력까지 대기
    cv2.destroyAllWindows()         #창닫기
else:
    print("Don't found image file")

Android HTML, 외부주소에서 JSON 파싱해 가져오기

Posted by PeEn
2019. 12. 28. 21:54 Programing/Android

activity_main.xml

더보기
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".List_Main">

    <TextView
        android:id="@+id/tvString"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:background="@drawable/bg"
        android:gravity="center"
        android:textColor="#ffffff"
        android:textSize="30sp"
        app:fontFamily="sans-serif-condensed-light" />
        
</LinearLayout>

 

MainActivity.java

더보기
public class MainActivity extends AppCompatActivity {
    private static String IP_ADDRESS = "PHP서버주소";
    private static String TAG = "그룹명";
    private static String filename = "파일명.php";
    private String mJsonString;
    private TextView tvString;
    
  	MainActivity.GetData task;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity.xml);

		tvString = (TextView) findViewById(R.id.tvString);

        //처음 시작될 때 AsyncTask 시작
        task = new GetData();
        task.execute("http://" + IP_ADDRESS + "/" + filename, "");

    }
   
   //PHP주소로부터 데이터를 받아오는 함수
   private class GetData extends AsyncTask<String, Void, String> {

        ProgressDialog progressDialog;
        String errorString = null;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();

            progressDialog = ProgressDialog.show(List_Main.this,
                    "Please Wait", null, true, true);
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            progressDialog.dismiss();
            Log.d(TAG, "response - " + result);

            mJsonString = result;
            showResult();

        }


        @Override
        protected String doInBackground(String... params) {

            String serverURL = params[0];
            String postParameters = params[1];


            try {

                URL url = new URL(serverURL);
                HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();


                httpURLConnection.setReadTimeout(5000);
                httpURLConnection.setConnectTimeout(5000);
                httpURLConnection.setRequestMethod("POST");
                httpURLConnection.setDoInput(true);
                httpURLConnection.connect();


                OutputStream outputStream = httpURLConnection.getOutputStream();
                outputStream.write(postParameters.getBytes("UTF-8"));
                outputStream.flush();
                outputStream.close();


                int responseStatusCode = httpURLConnection.getResponseCode();
                Log.d(TAG, "response code - " + responseStatusCode);

                InputStream inputStream;
                if (responseStatusCode == HttpURLConnection.HTTP_OK) {
                    inputStream = httpURLConnection.getInputStream();
                } else {
                    inputStream = httpURLConnection.getErrorStream();
                }


                InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
                BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

                StringBuilder sb = new StringBuilder();
                String line;

                while ((line = bufferedReader.readLine()) != null) {
                    sb.append(line);
                }

                bufferedReader.close();

                return sb.toString().trim();


            } catch (Exception e) {

                Log.d(TAG, "GetData : Error ", e);
                errorString = e.toString();

                return null;
            }

        }
    }


    private void showResult() {

        String TAG_JSON = "그룹명";
        String TAG_INDEX_NO = "field1";
        String TAG_S_DATE = "field2";
        String TAG_STIME = "field3";
        String TAG_ETIME = "field4";
       
        try {
            JSONObject jsonObject = new JSONObject(mJsonString);
            JSONArray jsonArray = jsonObject.getJSONArray(TAG_JSON);


            LastInt = jsonArray.length();

            for (int i = 0; i < jsonArray.length(); i++) {

                JSONObject item = jsonArray.getJSONObject(i);

				mJsonString = item.getString(TAG_INDEX_NO) +", "+ item.getString(TAG_S_DATE)
                +", "+item.getString(TAG_STIME)+", "+item.getString(TAG_ETIME);

            }
			tvString.setText(mJsonString);

        } catch (JSONException e) {

            Log.d(TAG, "showResult : ", e);
        }


    }

'Programing > Android' 카테고리의 다른 글

Android Intent startActivityForResult  (0) 2020.12.07
Android Dialog 화면 꽉채우기  (0) 2020.12.07
Android 리스트뷰  (0) 2019.12.28
assets 사전 insert DB  (0) 2019.12.09
Adapter, GridView와 ListView 적용법  (0) 2019.11.25

Android 리스트뷰

Posted by PeEn
2019. 12. 28. 21:38 Programing/Android
  • activity_main.xml

더보기
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".List_Main">

    <TextView
        android:id="@+id/btnHome"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:background="@drawable/bg"
        android:gravity="center"
        android:textColor="#ffffff"
        android:textSize="30sp"
        app:fontFamily="sans-serif-condensed-light" />


    <View
        android:id="@+id/view4"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#000000" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"

            android:gravity="center"
            android:text="NO"
            android:textColor="#E91E63"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"

            android:gravity="center"
            android:text="DATE"
            android:textColor="#E91E63"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/textView22"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"

            android:gravity="center"
            android:text="START"
            android:textColor="#E91E63"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/textView23"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"

            android:gravity="center"
            android:text="END"
            android:textColor="#E91E63"
            android:textSize="18sp" />

    </LinearLayout>

    <View
        android:id="@+id/view5"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#000000" />

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swipe_layout"
        android:layout_width="match_parent"
        android:layout_height="450dp">

        <ListView
            android:id="@+id/listView_main_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" />
    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

    <View
        android:id="@+id/view2"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#000000" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="샴푸"
            android:textColor="#000000"
            android:textSize="60dp" />

        <TextView
            android:id="@+id/textView7"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="트리트먼트"
            android:textColor="#000000"
            android:textSize="60dp" />

        <TextView
            android:id="@+id/textView8"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="바디워시"
            android:textColor="#000000"
            android:textSize="60dp" />
    </LinearLayout>

    <View
        android:id="@+id/view"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#000000" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/tvSam"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:textColor="#000000"
            android:textSize="90dp" />

        <TextView
            android:id="@+id/tvTri"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:textColor="#000000"
            android:textSize="90dp" />

        <TextView
            android:id="@+id/tvBod"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:textColor="#000000"
            android:textSize="90dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal">

        <Button
            android:id="@+id/btnReSam"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#000000"
            android:text="리필"
            android:textColor="#ffffff" />

        <Button
            android:id="@+id/btnReTri"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#000000"
            android:text="리필"
            android:textColor="#ffffff" />

        <Button
            android:id="@+id/btnReBod"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#000000"
            android:text="리필"
            android:textColor="#ffffff" />
    </LinearLayout>

</LinearLayout>

  • List_Main.java
더보기
public class List_Main extends AppCompatActivity {

    private SwipeRefreshLayout mSwipeRefreshLayout;

    private ListAdapter adapter;
    private ListView listView;
    private String result_data;

    int LastInt;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_main);

        listView = (ListView) findViewById(R.id.listView_main_list);

        mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {


                mSwipeRefreshLayout.setRefreshing(false);
            }
        });
    }

    public void setList(){
        for (int i = 0; i < jsonArray.length(); i++) {
					//데이터 가져와 PersonalData라는 Class의 생성자를 통해 변수에 데이터를 넣는다. 한번에 데이터를 전달달하
                    PersonalData personalData = new PersonalData();
                    personalData.setIndex_no(i + 1 + "");
                    personalData.setS_date(s_date);
                    personalData.setStime(stime);
                    personalData.setEtime(etime);
					//데이터 어뎁터에 추가
                    adapter.addItem(personalData);
              		}
            //리스트뷰에 어뎁터 적용
    		listView.setAdapter((android.widget.ListAdapter) adapter);
    }
    
}
  • item_list_data.xml
더보기
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:tools="http://schemas.android.com/tools"

    android:gravity="center"
    android:orientation="vertical">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView_list_id"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:textColor="#000000"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/textView_list_date"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:textColor="#000000"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/textView_list_stime"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:textColor="#000000"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/textView_list_etime"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:textColor="#000000"
            android:textSize="18sp" />

    </LinearLayout>
<!--
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"

            android:gravity="center"
            android:text="SHAMPOO"
            android:textColor="#E91E63"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"

            android:gravity="center"
            android:text="RINSE"
            android:textColor="#E91E63"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"

            android:gravity="center"
            android:text="BODY"
            android:textColor="#E91E63"
            android:textSize="18sp" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView_list_one"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:textColor="#000000"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/textView_list_two"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:textColor="#000000"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/textView_list_tree"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:textColor="#000000"
            android:textSize="18sp" />

    </LinearLayout>
!-->
</LinearLayout>
  • ListAdapter.java
더보기
package kr.ac.jj.hackathon113app;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import java.util.ArrayList;

public class ListAdapter extends BaseAdapter {

    private ArrayList<PersonalData> listCustom = new ArrayList<>();

    // ListView에 보여질 Item 수
    @Override
    public int getCount() {
        return listCustom.size();
    }

    // 하나의 Item(ImageView 1, TextView 2)
    @Override
    public Object getItem(int position) {
        return listCustom.get(position);
    }

    // Item의 id : Item을 구별하기 위한 것으로 position 사용
    @Override
    public long getItemId(int position) {
        return position;
    }

    // 실제로 Item이 보여지는 부분
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CustomViewHolder holder = new CustomViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list_data, null, false);
			//layout.item_list_data.xml에 있는 텍스트뷰 변수로 연결
            holder.Index_no = (TextView) convertView.findViewById(R.id.textView_list_id);
            holder.s_date = (TextView) convertView.findViewById(R.id.textView_list_date);
            holder.s_stime = (TextView) convertView.findViewById(R.id.textView_list_stime);
            holder.e_stime = (TextView) convertView.findViewById(R.id.textView_list_etime);
            convertView.setTag(holder);
            
        } else {
            holder = (CustomViewHolder) convertView.getTag();
        }
		//PersonalData 생성자 불러 변수에 추가
        PersonalData dto = listCustom.get(position);
        holder.Index_no.setText(dto.getIndex_no());
        holder.s_date.setText(dto.getS_date());
        holder.s_stime.setText(dto.getStime());
        holder.e_stime.setText(dto.getStime());

        return convertView;
    }

    class CustomViewHolder {
    	//텍스트뷰 변수선언
        TextView Index_no;
        TextView s_date;
        TextView s_stime;
        TextView e_stime;

    }

    // MainActivity에서 Adapter에있는 ArrayList에 data를 추가시켜주는 함수
    public void addItem(PersonalData dto) {
        listCustom.add(dto);
    }
}
  • PersonalData.java
더보기
public class PersonalData {
    private String index_no;
    private String s_date;
    private String stime;
    private String etime;


    public PersonalData(String index_no, String s_date, String stime, String etime) {
        this.index_no = index_no;
        this.s_date = s_date;
        this.stime = stime;
        this.etime = etime;
    }

    public PersonalData() {

    }

    public String getEtime() {
        return etime;
    }

    public void setEtime(String etime) {
        this.etime = etime;
    }

    public String getIndex_no() {
        return index_no;
    }

    public void setIndex_no(String index_no) {
        this.index_no = index_no;
    }

    public String getS_date() {
        return s_date;
    }

    public void setS_date(String s_date) {
        this.s_date = s_date;
    }


    public String getStime() {
        return stime;
    }

    public void setStime(String stime) {
        this.stime = stime;
    }

}

'Programing > Android' 카테고리의 다른 글

Android Dialog 화면 꽉채우기  (0) 2020.12.07
Android HTML, 외부주소에서 JSON 파싱해 가져오기  (0) 2019.12.28
assets 사전 insert DB  (0) 2019.12.09
Adapter, GridView와 ListView 적용법  (0) 2019.11.25
FCM 앱 알람  (0) 2019.11.02